Homosexuals across America consider San Francisco a "Gay Mecca" thanks to the rise of the distinctive gay community, primarily in the Castro District, centered on the block from upper Market Street to the intersection of Castro and 18th Streets. Some estimate that there are as many as 100,000 gay men and lesbians in San Francisco, out of a total population of approximately 750,000.
The Castro wasn't always a gay neighborhood. Until the early 1960s it was primarily white working-class, predominantly of Irish descent, and better known as "Eureka Valley." But as the post-WWII trend of white flight to the suburbs drew more and more older San Franciscan families out, new groups moved in behind them. Such in-migration was typically that of ethnic minorities, mostly blacks, Latinos and Asians. SF also became home to thousands of gays, and the Castro is the district in which they decided to spend their money, put down roots and make a home.
Hundreds of houses of prostitution flourished from the Gold Rush through the early 20th century, followed decades later by the rise of topless bars and strip joints, and the pornographic film industry, all contributing to a sexual openness that gave San Francisco a reputation directly challenging the sexual repressiveness that prevailed in the rest of the country.
World War II provided a big impetus for the development of San Francisco's gay community. One and a half million soldiers, 10%+ of which were homosexual, were able to find each other more easily in the marginal districts of San Francisco.
During the 1950s San Francisco also spawned the Beat Culture, which shared spaces and attitudes with the incipient gay culture. Allen Ginsberg, himself gay, wrote Howl and fought obscenity charges in 1957.
In 1962 police and alcohol control board harassment led to the establishment of the Tavern Guild, consisting of the owners of primarily gay and bohemian establishments. As the community developed, feasts, celebrations, street parties, public and private bars, and bathhouses and sex clubs, became the important forms of cultural expression and sociability. The hippie movement of the 1960s, anti-war and counter-culture movements in general provided a relatively pro-pleasure climate for gays.