After nearly five years of being the nation's least affordable housing market, San Francisco was stripped of its title by new leader Los Angeles in the third quarter, according to the National Association of Home Builders/Wells Fargo Housing Opportunity Index.

Overall, 58.3% of homes, both new and existing, that sold between July and September, were affordable to families earning a median income of $68,000. This is down quarter-over-quarter from the 59.4% of homes sold that were affordable to families earning the median income in the second quarter of 2017.

Median home prices grew

The national median home price increased to $260,000 from $256,000 in the second quarter, and mortgage rates increased slightly to 4.1% from 4.08% a quarter ago.

"Solid economic growth, along with ongoing quarterly job gains and rising household formations, are fueling housing demand," said NAHB Chief Economist Robert Dietz, in a press release. "Tight inventories and a forecast of rising mortgage interest rates through 2018 will keep home prices on a gradual upward path and slowly lessen housing affordability in the quarters ahead."

Youngstown, Ohio, led the nation as most affordable major housing market for the fourth consecutive quarter. Just over 90% of homes that sold in Youngstown in the third quarter were affordable to families earning the city's median income of $56,100.

Comparatively, in Los Angeles, only 9.1% of homes that sold in the city were affordable to families earning the area's median income of $64,300. San Francisco took second to Los Angeles, but was the nation's least affordable housing market for the past 19 consecutive quarters.