Rising home prices across California have eroded affordability to the point that only seven counties, including San Bernardino, have housing that a family earning the median income can afford to buy, according to a study released Thursday.

The analysis of second-quarter home prices and income levels in 32 counties by the Los Angeles-based California Association of Realtors found that 25 counties have housing stock priced out of the reach of families earning the median income.

Home prices have been rising around the state for several years and some markets have approached or matched their pre-recession highs.

“It’s pretty shocking,” said association Vice President and chief economist Leslie Appleton-Young.

And the inventory of housing stock within the reach of first-time buyers is dwindling.

“I think that the big risk is with the millennials in California. Where are they going to live? There are some that have parents that can help them with the down payment. They are the lucky ones. But the others are on their own,” Appleton-Yound said.

For example, less than 33 percent of the state’s inventory of available single-family homes, condominiums and town homes for sale was priced at or below what a household earning the California median income of $60,244 could afford, the association said.

“The significant disparity between what homebuyers can realistically afford and actual home price is discouraging,” association President Chris Kutzkey, said in a statement. “While housing is affordable in some regions of the state, California lacks an adequate supply and mix of affordable housing in locations where the majority of the state’s workforce resides.”

In the second quarter of 2015, the statewide median price of $446,980 was nearly 50 percent higher than what a California household with the median income could qualify for, the analysis said.

But in San Bernardino, where the median-household income is $50,640, wage earners at that level could afford a home costing 13 percent more than the median price of $222,310.

San Bernardino remains one of the state’s most affordable markets, according to the analysis.

Fifty-six percent of the county’s households could afford the median-priced home costing $223,830. And they needed a minimum annual income of $44,290 to qualify for the mortgage.

Not surprisingly, Los Angeles County is one of the state’s least affordable markets.

In Los Angeles, where the median income was $54,510, a family earning that amount could afford a home costing $275,530. But the median-priced home here was 58 percent higher at $436,010.

According to the affordability index, only 30 percent of households in the April through June quarter could afford a $445,190 median-priced home and they would need a minimum qualifying income of $88,080.

Not surprisingly, San Francisco was the least affordable county.

Households in San Francisco earning the median income of $75,910 were only able to afford a home costing $383,670, a difference of $863,900 or 225 percent. That’s compared with the actual second-quarter median home price of $1.2 million.

And during the second quarter, just 10 percent of families cold afford a median-priced home costing $1.35 million and they would need to earn a minimum annual income of $267,780 to qualify for the loan.