Miami grabbed the runner-up spot on a national ranking of the most expensive cities for home buyers, right behind Los Angeles.

Miami beat New York and San Francisco to claim a leading spot on home listing website RealtyHop's monthly Housing Affordability Index.

The average Miami household would need to spend 86% of its total annual income, or $2,439 a month, on mortgage and property taxes to buy into the market.

The study was released on the heels of Miami releasing an affordable housing master plan prepared by Florida International University's Jorge M. Pérez Metropolitan Center research institute with input from stakeholders.

The plan calls for the city to create an affordable housing finance corporation to administer funding, streamline the approval process for affordable housing, renovate the existing housing stock and build small-scale affordable housing near transit stops, according to the Miami Herald, which first reported on the Metropolitan Center report.

The RealtyHop affordability index generated its ranking by comparing Miami's median annual household income of $33,999 with the median for-sale home price of $500,000. New York-based RealtyHop then factored in property taxes and a mortgage, assuming the typical buyer took out a 30-year mortgage at 4.5% interest after putting down 20%. Expenses such as utility, water and sewer and maintenance aren't included in the housing costs.

In Los Angeles, which consistently has ranked as least affordable, the median for-sale home price is $906,000 but the city has a higher median household income at $54,501.

In third-ranked New York, the median home price is $900,000 and the median income is $57,782. In fourth-ranked San Francisco, the median home price is nearly $1.5 million but the median household income there is $96,265.

Miami assumed the runner-up spot in December after ranking as third least affordable for at least the previous two months.

RealtyHop only considers the 100 most populous U.S. cities.

The most affordable city in the study was Detroit. A home buyer in Detroit would spend a mere $302 a month on housing, or 13% of total annual income. The median home price is $50,000, and the median household income is $27,838.

Other ranked Florida cities are Hialeah at 11, Tampa at 31, Orlando at 43, St. Petersburg at 57 and Jacksonville at 88.