Anna Slavicek refuses to leave the Mission. As escalating housing costs drive her fellow teachers out of San Francisco, Ms. Slavicek stays put, determined to remain in the historic neighborhood where she has lived and taught for 22 years. To make rent, she shares a two-bedroom apartment with two other women.

“It’s very difficult to be an adult and have to share your space, and not to have [financial] security and not be able to buy a home,” says Slavicek.

But the alternative – abandoning her students and her community – is equally untenable to her. “I feel that we absolutely have the right to live in the community in which we work,” she says. “And it’s much better for our students if we are part of the community.”

Slavicek embodies a vexing reality for many Americans, not just in San Francisco, but also in other major urban centers across the United States. Over the past decade, the promise of good jobs, a diverse culture, boutique restaurants, and a high quality of life has lured people young and old back into cities. The urban renaissance has been one of the nation’s great postwar success stories.

SEAN GALLUP/GETTY IMAGES/FILE Residential houses line a street in the Mission District of San Francisco, where home prices are booming.

But the revival has also come with its share of problems – including, increasingly, the punishing cost of a home or apartment. The great reverse migration back into cities, coupled with rising construction costs and a dearth of places to build, has conspired to drive housing costs to historic highs.

And in many cases the squeeze has fallen hardest on the working middle class. True, low-income residents and immigrants – often priced out of neighborhoods they have lived in for generations – bear much of the burden for the platinum mortgages and rent bills, as they have in such housing cycles throughout history. But public-service workers, police, teachers like Slavicek, and other middle-income residents – lacking the welfare support and housing assistance of the very poor – are being hit particularly hard. They are increasingly being forced to make a fundamental choice: keep the jobs they have and settle for interminable commutes and smaller living spaces, or relocate to more affordable cities altogether.

“We have a tidal wave of people wanting to live an urban experience, and that’s a great thing,” says Peter Cohen, co-director of the Council of Community Housing Organizations, a nonprofit coalition of housing developers and tenant advocates in San Francisco. But, he adds, “We can’t just sit back and let that turn into another feast-or-famine, winner-loser situation based on economic privilege.”

US Census Bureau statistics show that in cities such as San Francisco, New York, Boston, and Seattle the number of low-income and affluent households has been rising while the population of middle-income residents appears to have been declining. This has led to a rising gap between the rich and the poor, tilting some cities toward a “barbell economy” – one with big populations at the two extremes and no middle – similar to many third-world cities.

Experts say the trend not only runs counter to the deeply American belief that hard work pays off; in the long run, it could also cost top cities the economic, racial, and cultural diversity that makes them so desirable. “We are seeing an exodus of families and single folks who simply cannot keep up economically with the increasing cost of housing,” Mr. Cohen says. “With this displacement along class and race lines, we turn our cities into ... wealthy enclaves. We can’t allow that to happen.”

￼TONY AVELAR/SPECIAL TO THE CHRISTIAN SCIENCE MONITOR/FILE Jessica Beard in her apartment in San Francisco.

As the home of companies such as Uber, Airbnb, and Yelp, San Francisco is the world’s de facto capital of the sharing economy. It has also become the urban hub of Silicon Valley. As a result, the city swarms with software engineers and entrepreneurs, many of whom have deep pockets.

The price of the city’s houses, from the ornate Victorians of Nob Hill to the Italianate residences of the Mission District, reflects the new affluence. The median home value in San Francisco now stands at $765,700 – 10 times the city’s median household income, according to the census. As of March, the median rent for a one-bedroom apartment was $3,590 a month. With the median income in the city being $78,400 a year, this means the average household can end up spending as much as half its earnings on housing.

Not surprisingly, many working-class and even middle-class people are fleeing the city as a result. Between 1999 and 2014, San Francisco added 10,000 low-income and more than 8,000 affluent households. But it lost 10,000 households that earned between $45,000 and $99,999, census data shows.

Dianne Brennan was one who considered moving out. She teaches autistic students in the San Francisco Unified School District. Threatened with eviction from her Mission District apartment, Ms. Brennan used all her resources – social media, Craigslist, e-mails to friends – and found a relatively affordable shared apartment in East Oakland.

But she soon discovered her daily commute on public transportation would be as long as three hours a day. Even buying a car wouldn’t have made much of a difference. “I had to decline it,” she says.

Similar dynamics are playing out in other cities. Between 2006 and 2012, half of the 10 wealthiest metropolitan areas in the US, including Boston, saw middle-class residents lose a greater share of income than the national average, according to census numbers.

“We see it with some of our lower-paid school employees, in City Hall, our youth and family workers, street workers,” says Jennifer Springer, director of field operations and general counsel for the Service Employees International Union (SEIU) Local 888, which represents public-service workers in New England. “They’re definitely facing struggles.”

For one employee in the payroll department at the City of Boston’s Emergency Medical Services, the biggest obstacle to finding a home was coming up with first month’s rent, last month’s rent, and a security deposit – in other words, three times the unit’s $1,400 monthly price tag – upon signing the lease. “It becomes overwhelming,” says the employee, who asked not to be named for fear of losing her job.

Leaving the city for a cheaper location was not an option, she says, because a local ordinance requires city employees to live within Boston’s borders. Nor did she qualify for a subsidy under Section 8 housing, which requires a yearly income of less than $39,650 for a family of three. Her $1,000-a-week paycheck – with which she supports her grandson and daughter, who is in trade school – pushes her above the limit.

Only with the help of her union did she manage to come up with the money for her apartment in Dorchester, a predominantly working-class neighborhood south of downtown Boston.

High housing costs have other deleterious effects as well. Frequent moving and overcrowded homes have been shown to negatively affect children’s performance in school. The stress of looking for new housing, facing foreclosure or eviction, and enduring long commutes has also been linked to health disorders.

“All of it – the uncertainty and stress of where to live, of how to make ends meet, pay utilities, put food on the table – these are devastating choices people have to make,” says Amie Fishman, executive director of the San Francisco-based Non-Profit Housing Association of Northern California. For those who get evicted or priced out of a neighborhood, she says, “you lose not just your home but your network, your support systems, the predictability of your life.”

MELANIE STETSON FREEMAN/STAFF Bi Hua Huang, a Chinese immigrant, sits in her daughters’ bedroom in the Chinatown neighborhood of Boston. The family is having trouble affording rent – even though both parents work.

Those factors are why Bi Hua Huang fights to stay in Boston’s Chinatown, despite the neighborhood’s rising rent. She relies on her in-laws, who live nearby, to care for her two young daughters while she and her husband are at work.

Ms. Huang runs the cash register at a local restaurant, the Chinatown Cafe, from 10 a.m. to 8:30 p.m., six days a week. Together, she and her husband, who also works in the restaurant industry, make just enough – about $2,200 a month – to pay $1,350 for a two-bedroom apartment a few blocks from her job.

The place is cramped. The narrow hallway that connects the living room to the bedrooms doubles as the kitchen. None of the rooms have closets, so the family members stow their clothes in stacked plastic bins. The lack of storage space also means the rest of their belongings – winter coats, a half-filled box of Pringles cans, a child’s bicycle – clutter the apartment. Though the family qualifies for public housing, Huang says the endless waiting lists and bureaucratic hassles have prevented them from living in a subsidized apartment.

“Life is really tough,” says Huang, who arrived in the US five years ago from China’s Guangdong province, through an interpreter. “I never thought housing would be so expensive and the conditions so bad. I didn’t imagine that’s what life in the US would be like.”

Others, like Stephen Yearwood in New York City, opt to face a grueling commute rather than spend too much of their paychecks on rent. Every morning, Mr. Yearwood spends an hour and a half traveling from his government-subsidized home in the Bronx to the apartment complex in Brooklyn where he works as a handyman. The commute is far from ideal, he says, but necessary: The average rent for a one-bedroom in Brooklyn – $2,590 a month – is something he could never afford on his $45,000 a year salary.

“I would love to live close to where I work,” says Yearwood. “But I’m happy to just be able to live here. Not many families are that fortunate.”

• • •

As housing costs push the working and middle classes out of cities or into poverty, urban areas risk losing the diversity that make them so captivating in the first place.

Already San Francisco and Boston – which rank among the richest cities in America because of their concentration of high-tech, health-care, and other industries – have become places of stark inequality. In 2014, Boston’s wealthiest residents made nearly 18 times what its poorest workers earned – the biggest income gap of any city in the nation – while San Francisco’s richest outearned its poorest by a factor of 14.5, according to the Brookings Institution, a policy research center in Washington, D.C.

A separate study found that San Francisco’s Gini coefficient – a century-old standard used to measure an economy’s distribution of wealth – was nearly on par with that of a number of developing nations, such as Rwanda. (To be clear, the poor and rich in the US enjoy far more material wealth than their Rwandan counterparts. It’s the rich-poor gap that’s similar.)

Such inequality is indicative of populations at the extreme edges of the wealth spectrum: the very rich who can afford market-rate prices and the very poor who qualify for government housing, says Barry Bluestone, a professor of public policy and urban affairs at Northeastern University in Boston. “Everybody in between is being squeezed, and what you get is this tremendous inequality,” he says. “The problem with that is a city of the haves and have-nots is not the kind of city that I would like to live in.”

In San Francisco, that transformation may already be taking place. Cohen at the Council of Community Housing Organizations, for one, laments what he sees as the slow death of the city’s longstanding reputation as a place of sanctuary, a haven for bohemians and social outcasts. “If you were a poet and you didn’t have a real job, you came to San Francisco,” he says. “If you were gay and couldn’t come out of the closet, you came to San Francisco. If you were otherwise ostracized, abused – those are the people who made the great social fabric that we have. Those folks are now shut out.”

BRENDAN MCDERMID/REUTERS ‘The Charles,’ a luxury condominium building on New York’s Upper East Side, towers over other apartment complexes on First Avenue. Residences in the building, each of which takes up a full floor, start at $6 million. Two relatives bought the top six floors for $59 million.

Behind the rising prices is simple economics: too many people chasing too few affordable homes and apartments. Cities have become magnets both for young people looking for urban amenities and jobs in thriving industries as well as empty nesters looking for museums and good food. Demand, in other words, is soaring.

But rising construction costs – a result of expensive land, restrictive zoning laws, and strong demand for units with stainless steel appliances – have made it difficult for developers to build enough dwellings.

Take Boston, where a single family-sized apartment of 1,600 square feet costs $438,000 to build, according to a report Mr. Bluestone co-wrote for the Boston Foundation. The hefty price tag meant that between 2010 and 2014, only 15,000 new housing units were built, even as the five-county region of Greater Boston grew by 67,000 households, the report found.

San Francisco saw a similar trend during the same period – only about 12,000 new units were built to accommodate a population that grew by 47,000 over five years, according to estimates by the Paragon Real Estate Group.

“Demand is driven by this demographic revolution, but we can’t fill that demand because the cost of production has gotten so high,” Bluestone says.

• • •

No easy solution exists to the housing crunch, but experts say things can be done to help ameliorate it. It will probably require a “bunch of little answers,” says Bluestone, that will have to come from a variety of places: city government, local unions, nonprofits, developers, and residents themselves.

In New York City, Mayor Bill de Blasio has pushed through an ambitious plan to build 200,000 affordable housing units over the next decade. It includes major zoning revisions that would mandate housing for low- and middle-income families and loosen some density and height requirements – provided developers include affordable and senior housing in their plans.

The initiative is controversial. New York Magazine calls it “the mayor’s version of Obamacare, an imperfect but monumental legacy program.” But city unions and top trade groups support the plan.

Boston’s Mayor Marty Walsh has also made workforce housing a cornerstone of his administration. He’s calling for the creation of 53,000 new units for people of varying income levels by 2030. As part of the plan, Mr. Walsh wants to put $28 million in funding to preserve or produce 837 affordable housing units through the city’s Department of Neighborhood Development and the Boston Housing Trust – a fund developed in partnership with SEIU Local 888, the union that represents public-service workers.

San Francisco’s efforts to address the issue include offering loan and mortgage assistance for first-time homebuyers and providing support specifically for educators: In May, the city aims to restart its Teacher Next Door program, an initiative that grants local educators as much as $20,000 toward their first home.

“I think our district, along with other Bay Area districts, is concerned about this combination of high cost of living and dramatic teacher shortage,” says Gentle Blythe, a spokeswoman at the San Francisco Unified School District.

Other groups are looking beyond city borders to address the challenge. Seattle-area governments, nonprofits, and social-

investment firms are backing the Regional Equitable Development Initiative Fund. It offers early stage financing for affordable housing near transit lines to connect low-income and working-class residents living in communities outside the city with jobs, schools, and services in Seattle.

Private money is pouring in as well. Last year, for example, real estate investment firm Turner Impact Capital teamed up with Citi Community Capital, the University of Michigan’s endowment, and the Rockefeller Brothers Fund to create an investment fund to buy and manage as much as $1 billion of affordable apartment complexes for low- and middle-income people. They’re trying to earn a financial return while investing in something that benefits society.

“We don’t have the social and economic mobility in our country like the myth suggests we do: It’s harder than ever for someone [who is] low-income to get ahead, and a lot of the time, the middle are slipping backward, too,” says Rolf Pendall, director of the Metropolitan Housing and Communities Policy Center at the Urban Institute in Washington. “It’s time we make investments [in these issues] collectively. It’s time for a little more creativity around how to retain our cities’ value so we can have inclusion.”

Slavicek, the San Francisco schoolteacher, wouldn’t disagree. In the last year, she has cut down her teaching hours to spend more time rallying support for affordable housing. She’s helping organize protests, raise awareness about the issue, and fight for policy reform. To her, what’s at stake is the city’s workforce – the people who not only keep San Francisco’s economy running, but also give the city its character and spirit.

Get the Monitor Stories you care about delivered to your inbox. By signing up, you agree to our Privacy Policy

“Housing is our No. 1 issue now,” Slavicek says. “Our homes are not negotiable.”

[Editor's note: In the original, Peter Cohen was incorrectly identified. He is co-director of the Council of Community Housing Organizations, a nonprofit coalition of housing developers and tenant advocates in San Francisco.]