PALO ALTO — Few California communities have as many trappings of the good life as Palo Alto. The Silicon Valley suburb is home to two of the state’s highest-earning neighborhoods, top-performing public schools and tens of thousands of residents with graduate degrees — plus it neighbors Stanford, one of the country’s most prestigious universities.

But there’s another area in which Palo Alto ranks among the highest: its housing costs.

Palo Alto’s worsening affordability problem — its median home value is more than $3 million, according to real estate website Zillow — has been driven by an explosion in new jobs alongside a lack of sufficient home building to accommodate workers moving into the city, a dilemma also faced by other tech hubs across California. Now, one state lawmaker hopes to address the issue in Palo Alto and other suburban enclaves.

Sen. Scott Wiener’s Senate Bill 50 aims to spur home building by requiring local governments to relax construction restrictions near mass transit, and it contains a separate provision that would force wealthy communities near employment centers to allow apartments where only single-family homes are currently permitted, regardless of whether they’re close to rail or major bus lines.

Wiener, a Democrat from San Francisco, said the state can’t tackle its housing affordability problem or curb greenhouse gas emissions without a lot more building, including in neighborhoods that have a history of excluding anyone who can’t afford a single-family home.

“It’s no longer acceptable to attract tons of jobs while refusing to build housing,” Wiener said. “That isn’t sustainable. It doesn’t work. And it has to change.”

Palo Alto could face dramatic changes under Wiener’s bill. The city would have to allow four- to five-story apartment complexes next to its two stops on the Caltrain line that runs from San Francisco to San Jose. And because Palo Alto’s single-family neighborhoods are largely home to high-income earners with college educations and are close to well-paying jobs and high-ranking public schools, the legislation would require the city to allow apartment construction in most of those areas as well.

The prospect of significant transformation in Palo Alto has exacerbated existing tension over its changing suburban character in the face of an influx of tech jobs and rising housing costs. In recent years, residents have tried to cope with the situation in a variety of ways, including blocking low-income housing and office construction while also making it easier to build second housing units, or casitas, in their backyards.

Last month, Palo Alto Mayor Eric Filseth devoted much of his hourlong State of the City speech to discussing what he believes are the dangers of SB 50, arguing that local politicians are the only ones who understand how to plan their cities.

“You’re telling me that some guy with Google Maps in a basement in Sacramento is going to do that?” he said.

Leafy neighborhoods lined with Midcentury Modern homes and other single-family residences make up the bulk of Palo Alto, where suburbia is part of its mythology. The small garage where Bill Hewlett and Dave Packard came up with their first invention in the late 1930s still stands behind a sign from the National Register of Historic Places calling it the “Birthplace of Silicon Valley.”

Opponents of SB 50 in Palo Alto agree with Wiener that the imbalance between jobs and housing has led to the city’s affordability problem. But they disagree on the solution.

Greg Schmid, a 78-year-old retired economist, said the region should slow the expansion of large companies. Young, highly paid tech employees are overwhelming Palo Alto, he said, and adding to traffic congestion. The situation, he said, only works for the companies’ benefit and drives out families who earn less and could otherwise live in Palo Alto.

“The aggressive expansion of big business does not have any sensitivity to the need for a sustainable community,” Schmid said.

Schmid, a former city councilman, is one of the leaders of Palo Altans for Sensible Zoning, a political action committee that successfully lobbied last year to halve the growth of the city’s allowable office space.

“We have too many jobs,” he said.

But others believe the real issue is that Palo Alto residents want to prevent more people from living in their community.

“Stopping jobs? That’s a champagne problem, really,” said Candice Gonzalez, the former president of nonprofit affordable housing developer Palo Alto Housing Corp.

Gonzalez’s organization planned to build 60 apartments for low-income senior citizens along with a dozen single-family homes in Palo Alto. But voters in 2013 overturned their approval, with opponents arguing that the plan would lead to too much density. Last year, the city signed off on another developer’s plan to build 16 single-family homes on the site instead.

“It’s just a drawbridge mentality,” said Gonzalez, who now works for a for-profit home builder. “People have theirs and don’t care if anybody else has it.”

SB 50’s provision to force suburbs to increase housing construction will change many other communities near job centers — predominantly along California’s coastline.

The legislation has the potential to quadruple housing production in affected Bay Area communities, with more than three-quarters of that new growth in wealthier neighborhoods — a finding driven by the provision increasing suburban density, according to a report from UC Berkeley’s Urban Displacement Project.

Wiener’s bill does not outline which affluent neighborhoods will be affected. But he plans to align the bill’s language with definitions for “areas of opportunity” recently developed by the Urban Displacement Project and other Berkeley researchers, which take into account a neighborhood’s income and education levels, commute patterns and public school performance.

Under these definitions, in Northern California, Marin County enclaves such as Mill Valley and Tiburon are considered areas of opportunity, as are much of San Francisco’s west side and smaller communities along the peninsula between that city and San Jose.

In Southern California, small coastal cities such as Manhattan Beach, Hermosa Beach and Redondo Beach would be affected, as would some West Los Angeles neighborhoods, Burbank, Lakewood and Beverly Hills.

Beverly Hills Mayor John Mirisch also denounced the legislation during a recent public speech. He handed out noisemakers, asking the crowd to shake them whenever he said “Sacramento politicians” to muffle those words.

Mirisch said Wiener’s bill is an attempt to demonize single-family neighborhoods for the benefit of real estate industry profits.

“I feel that overreach by Sacramento politicians is a threat not only to our community, but to every community in the state,” he said.

Wiener said he intended for his bill to push high-income neighborhoods zoned only for single-family homes to make room for apartments as redress for historical wrongs.

Government-sponsored lending practices through the middle of the 20th century ensured that access to most single-family neighborhoods was only available to white people, allowing them to build wealth through homeownership that others couldn’t. In Palo Alto, the Federal Housing Administration blocked the development of an integrated subdivision in the 1940s, only financing the project after it was reserved for white families, according to “The Color of Law: A Forgotten History of How Our Government Segregated America.”

Richard Rothstein, the book’s author and a senior fellow at the Haas Institute for a Fair and Inclusive Society at UC Berkeley, said allowing apartments in communities like Palo Alto is necessary but does not do enough to resolve long-standing inequities.

“If that’s all that’s done, it will increase housing opportunities for those who can afford market-rate housing, even smaller market-rate housing,” Rothstein said. “It doesn’t include opportunities for low-income African Americans or low-income people in general.”

SB 50 also requires developers to set aside a portion of projects larger than 10 units for low-income residents, and it defers to city policies that call for higher percentages.

Even high-income earners find it hard to live in Palo Alto. Three years ago, Kate Downing, an attorney who was then a member of Palo Alto’s planning commission, wrote a widely shared post on Medium detailing her reasons for leaving the city. At the time, she and her software engineer husband were working in town and renting a four-bedroom home in Palo Alto with another couple for $6,200 a month.

But they wanted to have children.

“If you’re a professional in the Bay Area, you can afford it because you can have roommates,” said Downing, 33. “But when you want to have a family, you lose roommates that pay you money, and you end up having roommates you pay money to.”

Downing and her husband bought a four-bedroom home in Santa Cruz for $1.6 million and now live there with their 18-month-old son.

Preventing people like Downing and others from leaving the community is the reason Adrian Fine, Palo Alto’s vice mayor, supports SB 50. On a recent morning, Fine walked in the neighborhood surrounding the city’s main Caltrain station along University Avenue, an area that could see a resurgence of mid-rise apartments under the legislation. Small apartment buildings are no longer allowed under zoning codes because past city leaders decreased density, he said.

Fine said Palo Alto should allow more homes in those neighborhoods, even if they’re mostly affordable only to higher-income earners. Doing so, he said, would help prevent the wealthy from gobbling up the existing housing stock, lead to more low-income housing through rules requiring developers to reserve part of their projects for less affluent residents, and get people out of their cars, which helps the climate.

“If we don’t do three to five stories near transit, where are we going to do it?” he said.

Still, Fine feels the part of the bill that would increase density across the city’s single-family neighborhoods — and farther away from train stops — needlessly inflames residents concerned about the character of their community.

“It’s a little bit of sticking a thumb in the eye to places like Palo Alto,” he said.

Wiener said he’s planning to make changes to the bill so that areas at risk of wildfires wouldn’t be subject to density increases, even if they’re near jobs. But he said Palo Alto’s leaders have proved they won’t do enough to support home building, affordable or otherwise.

The city, Wiener said, hasn’t increased density, beefed up policies for developers to set aside housing for low-income residents or adopted rent control.

“They have these tools and they haven’t used them,” he said.