LGBTQ people are well documented in various artworks and literary works of Ancient India, with evidence that homosexuality and transsexuality were accepted by the major dharmic religions. Hinduism and the various religions derived from it were not homophobic and evidence suggests that homosexuality thrived in ancient India until the medieval period. Hinduism describes a third gender that is equal to other genders and documentation of the third gender are found in ancient Hindu and Buddhist medical texts. The term "third gender" is sometimes viewed as a specifically South Asian term, and this third gender is also found throughout South Asia and East Asia.

It's likely that parts of north western fringes of Indian empires were influenced by homophobia early on through Zoroastrianism (250 BCE) and Islam, both of which explicitly forbade homosexual sex, and that this influenced socio-cultural norms in that region. LGBTQ people in the Islamic communities were persecuted more severely, especially under the rule of the Mughals, which ruled over large parts of India and Central Asia (and ultimately derives from the Mongol Empire), though Mughal leaders largely tolerated the cultures of the various non-Muslim communities of India.

From the early modern period, colonialism from Europe also brought with it more centralized legal codes that imposed Christian-European morals that were homophobic in nature, including criminalizing sex between two people of the same gender, and criminalizing transsexuality.

In the 21st century following independence, there has been a significant amount of progress made on liberalizing LGBTQ laws.

Ancient period Hinduism provides a wide breadth of literary and artistic sources showing LGBTQ life in Ancient India. Hinduism does not have explicit morals condemning homosexuality nor transsexuality, and has taken various positions on the topic, ranging from containing positive descriptions of homosexual characters, acts and themes in its texts to being neutral or antagonistic towards it. The concept of sexual minorities was widely known in the prevailing Hindu culture by the time Gautama Buddha founded his philosophies, and homosexuality was also thought to be viewed positively in Buddhism

The Kama Sutra is an ancient text dealing with kama or desire (of all kinds), which in Hindu thought is one of the four normative and spiritual goals of life. The Kama Sutra is the earliest extant and most important work in the Kama Shastra tradition of Sanskrit literature. It was compiled by the philosopher Vatsyayana around the 4th century, from earlier texts, and describes homosexual practices in several places, as well as a range of sex/gender 'types'. The author writes that these relations also involve love and a bond of trust.

The author describes techniques by which masculine and feminine types of the third sex (tritiya-prakriti), as well as women, perform fellatio.Danielou, Alain. The Complete Kama Sutra, Part Two, Chapter Nine, entitled "Superior Coition or Fellation [Auparishtaka]. Rochester, VT: Park Street Press, 1994. The Second Part, Ninth Chapter of Kama Sutra specifically describes two kinds of men that we would recognize today as masculine- and feminine-type homosexuals but which are mentioned in older, Victorian British translations as simply "eunuchs." The chapter describes their appearances – feminine types dressed up as women whereas masculine types maintained muscular physiques and grew small beards, mustaches, etc. – and their various professions as masseurs, barbers and prostitutes are all described. Such homosexual men were also known to marry, according to the Kama Sutra: "There are also third-sex citizens, sometimes greatly attached to one another and with complete faith in one another, who get married together." (KS 2.9.36). In the "Jayamangala" of Yashodhara, an important twelfth-century commentary on the Kama Sutra, it is also stated: "Citizens with this kind of homosexual inclination, who renounce women and can do without them willingly because they love one another, get married together, bound by a deep and trusting friendship."Danielou, Alain. The Complete Kama Sutra. Rochester, VT: Park Street Press, 1994.

The Arthashastra, a 2nd century BCE Indian treatise on statecraft, mentions a wide variety of sexual practices which, whether performed with a man or a woman, were sought to be punished with the lowest grade of fine. While homosexual intercourse was sanctioned, it was treated as a very minor offence, and several kinds of heterosexual intercourse were punished more severely.

Sex between non-virgin women incurred a small fine, while homosexual intercourse between men could be made up for merely with a bath with one's clothes on, and a penance of "eating the five products of the cow and keeping a one-night fast" – the penance being a replacement of the traditional concept of homosexual intercourse resulting in a loss of caste. These are punishments listed for the use of the priestly class of people (traditionally monks) for both heterosexual and homosexual sexual misconduct, where the punishments for heterosexual misconduct were often more severe than homosexual misconduct.

Medieval period A large number of erotic artwork depicting homosexuality can be found on numerous temples throughout India, including Khajuraho temple sculptures built in the 700s, and the Sun temple in Konark built in the 1200s.

Early modern period Early Mughal emperors were often tolerant of the Hindu society and allowed them to live as they wanted to.

References to homoeroticism are found throughout Indian Islamic culture. Mughal artwork and poetry contains many examples of celebrations of male homoeroticism. The first Mughal Emperor Babur wrote about his passion and desire for a male "lover" called Baburi (who was already an adult when the Emperor ascended the throne) in his autobiography Baburnama. He wrote :

1500s In 1528, J.M. John Marshal, doctoral research scholar based in the Department of History, Goa University, Taleigao, recorded in his book Homosexuality in Early Modern Goa the judiciary of Goa punished a muslim man for sodomy.

In 1560, homosexuality was prohibited for much of the existence of the Portuguese Empire. The Portuguese introduced Goa Inquisition to deal with problems of sodomy and prosecuted homosexuals or people engaged in same sexual activity.

1600s In 1607, Marshal, in his research, noted the case of Alberto Homemo, a German soldier in the Portuguese army, who was executed without trial. "The inquisition record states that Alberto, induced by devil, committed the ‘horrible and abominable vice of sodomy’ since he was 16 years old, habitually with many men, also while he was serving in the North (Portuguese Bombay) as well as many cities where he lived and when he was sent in the army of Malacca too. The inquisition declared him being infamous(notoriously evil), confiscated his goods and ‘relaxed’ him to secular justice to be burnt alive. The sentence was written by the Inquisitor Jorge Ferreira, dated 09-12-1607."

In 1667 or 1675, the Fatawa-e-Alamgiri of the Mughal Empire mandated a common set of punishments for homosexuality, which could include 50 lashes for a slave, 100 for a free infidel, or death by stoning for a Muslim. While pederasty was often considered as "pure love" and prevalent among those from Central Asia, in India, however, this was generally unheard of. For example, the governor of Burhanpur was murdered by a boy servant with whom he tried to be intimate. Muslim Urdu poetry of the era sometimes expressed homoerotic viewpoints reminiscent of bromances, but these were not explicitly homosexual in nature.

1700s In 1723, the scholarly research of Mir Taqi Mir's poems and ghazals showed allusions and references to beloved male lovers. Ruth Vanita, Saleem Kidwai, p 119, Same-sex love in India: readings from literature and history also asserts that Mir's poetry "represents homoeroticism" and that he, along with others, "developed a discourse of erotic commentary on young males."

In 1791, homosexuality was decriminalised in the French Indian territories of Pondicherry.

1800s In 1861, the British Raj, in directly governed British territories, replaced the criminal offences and punishments set out in the Mughal Fatawa 'Alamgiri, with those of the 1862 Indian Penal Code, section Section 377 covering homosexuality. The law stated: "Whoever voluntarily has carnal intercourse against the order of nature with any man, woman or animal, shall be punished with [imprisonment for life], or with imprisonment of either description for a term which may extend to ten years, and shall also be liable to fine. Explanation: Penetration is sufficient to constitute the carnal intercourse necessary to the offense described in the section." The law was drafted by Thomas Babington Macaulay, who based it on anti-sodomy laws that already existed in Britain." The term "order of the nature" was never defined, hence considering its vagueness, the law could apply to virtually any sexual act considered against this order by the British Judiciary, which included all penetrative sexual acts, except for vaginal penetration by a man. There are not many cases that were tried under this law, though, as there were only exist 5 recorded cases that were tried under Section 377 India till 1920. The law had a larger impact on social values than legal ones. The anti-sodomy law in Britain and, in turn, India, was inspired by the 'purity campaign', an ideology that aimed at repressing sexual conduct in British society. This campaign also changed the perception and beliefs about sexualities in the European society.

In 1871, the hijra were labelled a "criminal tribe" in the Criminal Tribes Act (1871). Eventually, they were subjected to compulsory registration, unlawful monitoring, and stigmatization. British Lieutenant-Governor Edmund Drummond (1814–1895) framed the anti-hijra campaign as a necessary project of "extinguishment" and "extinction." The surveillance methods were enacted over communities with hopes to eradicate hijras permanently.

In 1884, the sodomy-related case to be prosecuted under British rule in India was the case of Khairati vs Queen Empress. Khairati was first called on by the police when he was seen dressed as a woman and singing with a group of women in Moradabad. The case was brought to the Allahabad high court, where Khairati was forced to undergo a medical examination and was found to have an 'extended anal orifice' which was a sign of a 'habitual catamite'. Cross-dressing was, again, used as evidence to support this argument. Cross-dressing was normal in the indigenous culture in India, but since this did not fit the moral standards of sexuality of Brits and due to the ambiguity of Section 377, Khairati was arrested and prosecuted in court. Khairati was later acquitted on appeal in the Allahabad high court.

20th Century

1920s On 31 May 1924, Matvala, a Calcutta biweekly, published a story titled "Chocolate" by Pandey Bechan Sharma "Ugra".In December 1924, after the publication of Chocolate Charcha Ugra was charged with sedition for editing the victory issue of Swadesh and sentenced to nine months in prison under section 124A of the IPC.

In 1927, Ugra wrote Hey Sukumar (O Beautiful Young Man!), Vyabhichari Pyar (Dissolute Love), and Jail Mein (In Prison) and published them in the short fiction Chocolate: And Other Writings On Male Homoeroticism in Calcutta.

1930s In 1936, Raghupati Sahay, also known by his pen name Firaq Gorakhpuri, a professor of English at Allahabad University, published an article in defence of homosexual love. Talking about Ghazals he describes the depiction of homosexuality in poetry across time and cultures in the works of Sappho, Socrates, Saadi, Hafiz, Shakespeare, and Whitman.

1970s