THERE was a teenager in Arizona in the 1970s who “could no more imagine longing to touch a woman than longing to touch a toaster”. But he convinced himself that he was not gay. Longing to be “normal”, he blamed his obsession with muscular men on envy of their good looks. It was not until he was 25 that he admitted the truth to himself—let alone other people. In 1996 he wrote a cover leader for The Economist in favour of same-sex marriage. He never thought it would happen during his lifetime. Yet now he is married to the man he loves and living in a Virginia suburb where few think this odd.

The change in attitudes to homosexuality in many countries—not just the West but also Latin America, China and other places—is one of the wonders of the world (see article). This week America’s Supreme Court gave gay marriage another big boost, by rejecting several challenges to it; most Americans already live in states where gays can wed. But five countries still execute gay people: Iran hangs them; Saudi Arabia stones them. Gay sex is illegal in 78 countries, and a few have recently passed laws that make gay life even grimmer. The gay divide is one of the world’s widest (see article). What caused it? And will tolerance eventually spread?

Two steps forward and one back

The leap forward has been startlingly quick. In the 1950s gay sex was illegal nearly everywhere. In Britain, on the orders of a home secretary who vowed to “eradicate” it, undercover police were sent out to loiter in bars, entrap gay men and put them in jail. In China in the 1980s homosexuals were rounded up and sent to labour camps without trial. All around the world gay people lived furtively and in fear. Laws banning “sodomy” remained in some American states until 2003.

Today gay sex is legal in at least 113 countries. Gay marriages or civil unions are recognised in three dozen and parts of others. In most of the West it is no longer socially acceptable to be homophobic. Gay life in China is now both legal and, in cities, undisguised. Latin America is even more gay-friendly: 74% of Argentines and 60% of Brazilians believe that society should accept homosexuality. Thais are more relaxed about transgender people than Westerners are. South Africa’s constitution is remarkably pro-gay. The young have tended to lead the way: although only 16% of South Koreans over 50 think that homosexuality should be accepted, 71% of 18-to 29-year-olds do.

Yet there are still parts of the world where it is not safe to be homosexual. Extra-judicial beatings and murders are depressingly common in much of Africa and in some Muslim countries. African gangs subject lesbians to “corrective rape”. In some countries persecution has intensified. Chad is poised to ban gay sex. Nigeria and Uganda have passed draconian anti-gay laws (though a court recently struck Uganda’s down). Russia and a few other countries have barred the “promotion” of homosexuality.

This is partly a reaction to the spread of gay rights in the West. Thanks to globalisation, people who live in places where everyone agrees that homosexuality is an abomination can now see pictures of gay-pride parades in Sydney or men marrying men in Massachusetts. They find this shocking. Meanwhile some homophobic Western preachers have gone to fire up anti-gay audiences in Africa, and American conservatives offer advice to countries thinking of drafting anti-gay laws.

Revulsion against homosexuals is ancient, deep and, in its way, sincere, even if some of the politicians leading the backlash do so for cynical reasons. By taking up arms against an imaginary Western plot to spread perversion, Vladimir Putin and Nigeria’s Goodluck Jonathan doubtless hope to distract attention from the corruption and incompetence of their own regimes. But they have picked their scapegoats shrewdly: 74% of Russians and 98% of Nigerians disapprove of homosexuality. In places like Indonesia, Senegal, Uganda and Malaysia the young are no more tolerant than the old—sometimes less so.

Nonetheless, there are reasons for optimism, at least in the long term. Urbanisation helps. It is easier to find a niche in a big, anonymous city than in a village where everyone knows your business. Gay life in the Indian countryside is still awful; in Mumbai or Delhi it is much easier, despite being illegal. In rural South Africa, to be openly gay is to court death; yet half of South Africans now say that their neighbourhood is a good place to be gay. As people move to cities, old traditions lose their grip; and by 2050 mankind is expected to be 66% urban, up from 54% today.

Emerging countries in Asia and Latin America have generally grown kinder to gay people as they have grown richer, more open and more democratic. The hope is that as Africa and the Arab world catch up, they will follow suit. Although religion is a barrier to tolerance—the more pious a society, by and large, the less enthusiastic it is about gay rights—it is not an insuperable one: plenty of devout nations, such as the Philippines and the United States, are friendly to gays these days.

Familiarity breeds tolerance

What could help spread tolerance? If the past half-century is any guide, the prime movers will be gay people themselves. The more visible they are, the more normal they will seem. These days 75% of Americans say they have gay friends or colleagues, up from only 24% in 1985. But it is hard to be the first to come out in a country where that means prison or worse.

Some Westerners would like to use aid budgets as leverage. That may have helped in Uganda, but attaching conditions to aid usually fails, and cutting it off may hurt the poor more than it helps gay people. It would be better to offer financial support to local gay-rights groups, to be generous when those persecuted for their sexual orientation seek asylum, to shame Western conservatives who encourage bigotry abroad and to buttress tolerance at home.

For those who cling to the notion of progress, it is hard to believe that tolerance will not spread. After all, gay people are not demanding special treatment, just the same freedoms that everyone else takes for granted: to love whom they please and to marry whom they love.