The US housing market has been taking a beating.

Home sales have been declining amid soaring home prices and rising mortgage rates, and affordability is especially acute among millennials, experts say.

But a number of large US cities have ample supply of homes that are affordable on the median household income for millennials, according to a study by real-estate brokerage Redfin.

Many are rust-belt economies that saw their populations decimated during the last recession as jobs evaporated but have since made a comeback amid one of the most robust employment markets in US history.

The US housing market continues to take a beating.

Home sales fell sharply in the second half of 2018, culminating in an especially bleak December: Existing-home sales in the US fell 10.3% from last year, the steepest decline in more than seven years, according to data released in January by the National Association of Realtors.

This week, the NAR released data showing that pending home sales fell 2.2% in December, the lowest point since 2014.

The reasons for the housing slowdown are myriad, but affordability concerns — especially among millennials — are playing a prominent role, with mortgage rates shooting up in 2018 amid a long-running ascent in home prices.

"In first half of 2018, prices were still going up pretty rapidly," Daryl Fairweather, chief economist at real-estate brokerage Redfin, told Business Insider. "In the second half prices pulled down a bit, but at the same time mortgage interest rates peaked."

Millennials — a generation of more than 70 million now in their 20s and 30s — have delayed buying a home later than their parents did, but their participation is critical for a robust housing market, experts say.

The generation, on the whole, prefers large cities. But bustling, coastal metro job centers like New York, San Francisco, and Los Angeles are among the most expensive to live in — and housing costs are a key reason why.

Home prices have shot up in those cities, and housing that's financially feasible on the median income is in slim supply, according to a study by Redfin.

The company analyzed the cities with the most and least amount of available affordable homes for sale at the end of 2018, comparing the housing supply with the median household incomes for the millennial cohort in each metro area. For the purposes of the study, they assumed a 20% down payment and a 4.64% mortgage rate, and monthly payment no greater than 30% of gross income. (Read more about Redfin's methodology.)

Los Angeles is the least affordable housing market right now, with only 19% of on-the-market homes affordable on the median income of $72,700 in 2018. San Jose (22%) and San Diego (24%) round out the top three among the least affordable, while San Francisco (37%) comes at No. 4 and New York City comes in at No. 7 (52%).

Overall, 67% of homes across all the metro areas Redfin looked at were affordable for millennials in 2018, down from 71% in 2017.

The good news: There are a number of major metro cities with ample supply of affordable homes, led by St. Louis, where 88% of the homes are affordable on the median income of $68,800. Pittsburgh (87.5%) and Columbus, Ohio (87%), round out the top-3.

A common theme among the most affordable cities, according to Fairweather: Many are rust-belt economies that saw their populations decimated during the last recession as jobs evaporated but have since made a comeback amid one of the most robust employment markets in US history — unemployment currently sits at 4%.

"Now those cities have rebounded, they have strong education and healthcare sectors and even technology," Fairweather said.

"It makes for a large supply of homes that are affordable if you're willing to live in those places," she added.

Read on for the full list of the 10 most affordable US cities for millennials to buy a home right now, according to Redfin's study.