The code was first used in the 1970s in the United States, Canada, Australia, and Europe, by gay and bisexual men seeking casual sex or BDSM practitioners.
The wearing of colored bandanas around the neck as a practical accessory was common in the mid- and late-nineteenth century among cowboys, steam railroad engineers, and miners in the Western United States.
[2] In the 1970s, the modern hanky code developed as a semiotic system of sexual advertising popular among the gay leather community of the United States[3] and cruising scene more broadly.
[6][7][8] However, other sources attribute the expansion of the original red–blue system into today's code to marketing efforts around 1971 by The Trading Post, a San Francisco department store for erotic merchandise, promoting handkerchiefs by printing cards listing the meanings of various colors.
Townsend noted that discussion with a prospective partner is still important because people may wear a given color "only because the idea of the hankie turns them on" or "may not even know what it means".