But a pandemic makes the equation different and hard to predict.

Ed Glaeser, an economics professor at Harvard University and the author of “Triumph of the City,” said watching the virus rip through cities was like going back in time. “It feels like it’s back to smallpox, it’s back to cholera,” he said.

“Cities were killing fields for centuries because of contagious disease,” he said, noting that the life expectancy of a baby born in a city in 1900 was seven years less than one born in a rural area. That gap disappeared by the 1920s, with the advent of modern water and sewer systems.

Over time, density became a boon, economically, socially, intellectually. Living in a city became a way to encourage health. People could walk where they needed to go and support one another in tight-knit social networks.

As the threat of the coronavirus lessens, some who fled major cities might elect to stay away while others will want to flock back to the perks of urban living.

“How people behave in a pandemic is probably not a great guide to how they want to live their lives in normal times,” Mr. Kolko said. “We are living in the middle of a grand forced experiment, but we really don’t know how the experiment is going to play out.”

So much is unknown. What will happen to housing prices, whose meteoric rise in cities was a big part of what was driving people away? Or immigration — one of the most important forces contributing to growth in cities? Already under the Trump administration those numbers were slowing. And cities themselves will likely look different, as they begin to plan for the possibility of pandemics.

One of the biggest questions for the future of cities is what becomes of low-wage workers, who are a big part of urban populations, but often work in jobs impossible to do from home. The restaurant industry, for example, employs more than 11 million people.