Photo: Noah Berger / Special To The Chronicle 2016

Cities in California must comply with a state law that requires them to make surplus public land available for low-cost housing, a state appeals court ruled Tuesday.

“The shortage of sites available for affordable housing development is a matter of statewide concern” that outweighs a city’s self-government interests, said the Sixth District Court of Appeal in San Jose. The court overturned a judge’s decision that would have allowed the city of San Jose to enforce a local ordinance that has less-stringent low-cost housing requirements, and more exemptions, than the state law.

The ruling, if it stands, will apply to 121 cities in California, including the largest cities that have their own self-governing charters, like San Francisco, and contain about half the state’s population, said affordable-housing advocates who challenged the ordinance.

San Jose, supported by the League of California Cities in court filings, was the first charter city to enact a housing law that conflicted with the state law. Non-charter cities are bound to follow the state law, under long-settled principles, and have not contested it.

The court’s decision “ensures that every local government does its fair share to help address the statewide affordable-housing crisis,” said Rebekah Evenson, a Bay Area Legal Aid attorney who argued in support of the state law.

A contrary ruling “would create two different Californias” covered by two sets of housing laws, said another attorney in the case, Michael Rawson of the nonprofit Public Interest Law Project. He said officials in some charter cities, like Oakland, were willing to follow the state law, but others would be free to adopt their own rules.

There was no immediate comment from the city attorney’s office. The city could seek review in the state Supreme Court.

The state law was enacted in 1982 and strengthened in 2014. It says local governments that own land or property they no longer need must offer it to developers that agree to make at least 25% of the housing units affordable for sale or rent by low-income households for at least 55 years.

If no such sale or lease of the property can be negotiated, the law allows the city to sell it on the open market, but if it includes 10 or more residential units, at least 15% must be at affordable prices.

San Jose’s ordinance, passed in 2016, declares the city’s commitment to affordable housing. But it allows the City Council to exempt individual properties from the state law’s requirements, and grants a five-year exemption from those requirements for all proposed high-rise rental housing in downtown San Jose. It also allows some property on city land to be sold at moderate-income prices rather than the low-income rates required by the state law.

Santa Clara County Superior Court Judge Theodore Zayner upheld the city’s law, ruling that a charter city’s sale of its own property was a subject of local concern, rather than a statewide matter governed by state law. The appeals court disagreed.

Although the city has a legitimate interest in disposing of its excess real estate, it must give way to the state’s concerns about “the well-documented shortage of sites for low- and moderate-income housing and the regional spillover effects of insufficient housing,” Justice Eugene Premo said in the 3-0 ruling.

He cited the Legislature’s statement, part of an amendment to the law due to take effect in January, that the shortage of sites available for affordable housing “is a barrier to addressing urgent statewide housing needs.”

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko