It also won the title of happiest city in America.

Fremont California

halbergman/Getty Images

Fremont, California, is home to happy families and happy people overall—at least, according to WalletHub. The personal finance site just announced its “Best Places to Raise a Family in the U.S.” rankings and the Northern California suburb was at the top for the fifth year in a row. The city was also ranked the “Happiest City in the U.S.” by Wallethub earlier this year. 

To come up with its rankings, WalletHub compared more than 180 U.S. cities based on 45 key metrics, like cost of housing, school-system quality, child-care costs, share of two-parent families, air and water quality, playgrounds per capita, and walkability.

So what makes Fremont an idyllic place to live? It all comes down to economics. Fremont has one of the highest median family incomes after adjusting for the cost of living; the second-lowest share of families living in poverty; and the fifth-lowest share of families receiving food stamps.

Fremont, California, is the best place to raise a family and the happiest city in the U.S.

Sundry Photography/Getty Images

Fremont also scored high marks in education—a high percentage of its public schools rated at least a 7 out of 10. And the city is a healthy one, with only 1.6% of children lacking health insurance and only 1.1% of the population lacking access to healthy food.

“Finding the best place to raise a family is difficult, between balancing an affordable cost of living with good educational opportunities, safety and enough recreation to keep kids entertained,” says WalletHub analyst Chip Lupo. “On top of all of these factors, people also often want to raise their children close to their extended family. Therefore, current or prospective parents can benefit from narrowing down their choices to a few of the best cities that are within a reasonable drive of their family.”

Fremont wasn’t the only Western city on the top 5 list: Irvine, California, ranked number 3 due to its safety. It has the second-lowest violent crime rate per capita, the 15th-lowest property crime rate per capita, and a low traffic fatality rate. Like Fremont, Irvine also has great schools with the third-highest percentage of schools with a 7 or more out of 10 rating.

Irvine was ranked number three.

Dee Liu/Getty Images

Take a look at the top 10 best cities and the 10 worst cities:

10 Best Cities for Families

1. Fremont, CA
2. Overland Park, KS
3. Irvine, CA
4. Plano, TX
5. Columbia, MD
6. Bismarck, ND
7. South Burlington, VT
8. Charleston, SC
9. Seattle, WA
10. Boise, ID

10 Worst Cities for Families

173. Hialeah, FL
174. Birmingham, AL
175. Shreveport, LA
176. Jackson, MS
177. Newark, NJ
178. Baltimore, MD
179. Gulfport, MS
180. Cleveland, OH
181. Memphis TN
182. Detroit, MI