“Sometimes I’ll be walking through the city and I’ll see a child and think, ‘Hey, wait a second. What are you doing here?’” said Courtney Nam, who works downtown at a tech start-up. “You don’t really see that many kids.”

There is one statistic that the city’s natives have heard too many times. San Francisco, population 865,000, has roughly the same number of dogs as children: 120,000. In many areas of the city, pet grooming shops seem more common than schools.

In an interview last year, Peter Thiel, the billionaire Silicon Valley investor and a co-founder of PayPal, described San Francisco as “structurally hostile to families.”

Prohibitive housing costs are not the only reason there are relatively few children. A public school system of uneven quality, the attractiveness of the less-foggy suburbs to families, and the large number of gay men and women, many of them childless, have all played roles in the decline in the number of children, which began with white flight from the city in the 1970s. The tech boom now reinforces the notion that San Francisco is a place for the young, single and rich.

“If you get to the age that you’re going to have kids in San Francisco and you haven’t made your million — or more — you probably begin to think you have to leave,” said Richard Florida, an expert in urban demographics and author of “The Rise of the Creative Class.”

Mr. Florida sees a larger national trend. Jobs in America have become more specialized and the country’s demography has become more segmented, he says. Technology workers who move to San Francisco and Silicon Valley anticipate long hours and know they may have to put off having families.

“It’s a statement on our age that in order to make it in our more advanced, best and most-skilled industries you really have to sacrifice,” Mr. Florida said. “And the sacrifice may be your family.”