LGBT literature in Spain, that is, literature that deals explicitly and primarily with characters and issues within the LGBT+ spectrum, is linked to the progressive social acceptance of sexual diversity in Spain. A great surge of authors, publications, awards, bookstores, and publishing houses—such as , the "first openly homosexual publishing house in Spain"—burst into the scene in the 1990s. In 1995, the Círculo de Bellas Artes itself in Madrid organized a series of 22 literary gatherings on this subject, which evidenced the flourishing of this type of literature.

Hispano-Arabic erotic poetry

In Al-Andalus, a type of poetry flourished that was highly refined and in which homoeroticism was a recurring theme. The Moorish kings themselves wrote this type of pederastic poetry, such as the Abbadid Al-Mu'tamid ibn Abbad of Seville and Yusuf III of the Nasrid Kingdom of Granada. It began to flourish in the first half of the 9th century, during the reign of Abd ar-Rahman II, emir of Córdoba. The fall of the Caliphate of Córdoba in the 11th century and the subsequent rule of the Almoravid dynasty and division into the taifa kingdoms decentralized culture all throughout the Al-Andalus region, producing an era of splendor in poetry. The Almohad invasion brought the emergence of new literary courts in the 12th and 13th centuries. Greater female autonomy in this North African ethnic group led to the appearance of a higher number of female poets, some of whom also wrote poems that sang of feminine beauty.

The homoeroticism present in Moorish poetry establishes a type of relationship like the one described in ancient Greece: the adult poet assumes an active role as opposed to an ephebe who assumes the passive role. This came to produce a literary cliché, that of the appearance of the bozo,  which allows, given the descriptive ambiguity of the poems, both in images and grammatical uses, for identifying the gender of the lover being described. Much of the erotic-amorous poetry of the period is devoted to the cupbearer or wine server, combining the bacchic (خمريات jamriyyat) and homoerotic (مذكرات mudhakkarat) genres.

19th century In realist literature, starting in the last third of the 19th century and for much of the 20th, homosexuality was seen in a negative light. This was influenced by the theses of Italian positivism (Cesare Lombroso considered that homosexuality led to crime), French degeneration (in authors such as Bénédict Morel, Valentin Magnan— who rejected homosexuality because its spread was contrary to procreation and therefore to the survival of the human species—and Max Nordau, who was inspired by these ideas for his 1892 essay Degeneration-Entartung, 1892–1893), and the German clinical school, with theses such as those of Dr. Karl Friedrich Otto Westphal, who maintained that homosexuality was a disease. In literature, homosexual characters appear infiltrated in all social classes and are presented, in general, as elements that threaten the good health of society—although there are exceptions, such as the chaplain who is the protagonist of Los pazos de Ulloa (1886) (translated into English with the title The House of Ulloa) by Emilia Pardo Bazán. There are examples of effeminate and perverse clergymen in works such as La regenta by Leopoldo Alas "Clarín". Also, the prototype of the degenerate bourgeois, whose pathology leads him to crime, can be found in the character of Maximiliano in Fortunata y Jacinta (1887) by Benito Pérez Galdós.

20th century up until 1975

In the early 20th century, Spanish homosexual authors such as Jacinto Benavente; Pedro de Répide; José María Luis Bruna, Marquis of Campo, , and had to choose between ignoring the subject of homosexuality or presenting it in a negative light.

At the same time, other non-gay authors continued to typify their characters according to 19th-century naturalist assumptions, which presented them as pathological beings. An example of this is the setting in the Jesuit seminary described by Ramón Pérez de Ayala in A.M.D.G., la vida en los colegios de jesuitas (1910), or the one in the novel La diosa razón (1918) by , who described in detail and from a naturalist perspective the influence of a family background to explain the homosexuality of one of the characters. Others, such as Eduardo Zamacois or , of a progressive and republican mentality, also judged homosexuality negatively as a vice that was typical of the upper-middle class, which had received a traditional education and had lived in a decadent environment, given to luxury and pleasure.

The only ones who openly published literature that dealt with homosexual themes outside of these topics were foreigners. Among them was Chilean author Augusto d'Halmar, who published in 1924. A very daring novel for the time, it tells of the attraction that a priest feels for a boy who sings in the choir of the church where he is assigned. Throughout the story—which has a tragic, but not moralistic ending—the characters' sexuality is gradually accepted. There is also Cuban author , who published El ángel de Sodoma (1928), and Uruguayan author Alberto Nin Frías, who published La novela del Renacimiento y otros relatos (1911), (1911), Marcos, amador de la belleza (1913), Alexis o el significado del temperamento urano (1932), and Homosexualismo creador (1932), the first treatise that painted homosexuality in a positive light.

Others took refuge in poetry, such as those belonging to the Generation of '27. Thus, the homosexual or bisexual authors of the Generation of '27 make up a long list, beginning with Federico García Lorca, Emilio Prados, Luis Cernuda, Vicente Aleixandre, and Manuel Altolaguirre. These poets were influenced by the great European homosexual writers, such as Oscar Wilde, André Gide (especially for his collection of essays Corydon), or Marcel Proust. Moreover, (1930) by Emilio García Gómez was also published after having been previewed in Revista de Occidente, which contained pederastic works by poets from Al-Andalus. The translation of Gide's articles was very controversial because of their evident homoerotic nature, and they had a powerful influence on the poetry of the time, especially in the qasidas of the by García Lorca, who also wrote three works with an explicitly homosexual theme, although none of them was published in Spain during the author's lifetime. These are: the poem Oda a Walt Whitman, the play El público, and the . The latter remained unknown until 1983, as his family refused to publish them.

In the early 20th century, there was also a timid awakening of lesbian literature. The first work to deal with the subject was Zezé (1909) by Ángeles Vicente. The first theatrical work dealing with the subject, by Cipriano Rivas Cherif, premiered in 1929. The only one who dared to publish homoerotic verses was Lucía Sánchez Saornil, although under the male pen name Luciano de San Saor. Other authors, such as Carmen de Burgos, made references to lesbianism in a more veiled manner. In other cases, the homosexuality of the authors is not manifested in their work (as was the case of writers Elena Fortún and Matilde Ras).

Towards the mid-1930s, a timid opening was taking place, which was cut short by the Civil War. After the war, with Lorca having been killed and most gay or bisexual poets in exile, gay culture retreated back to the obscure poetry of Vicente Aleixandre, who never publicly admitted to being gay. In 2016, many years after the poet's death, documents (such as letters and poems) with an explicit homoerotic content began to be made public, including the letters he wrote to his lover Carlos Bousoño.

Different was the case of , whose work is tinged with open homoeroticism, although it was less widely known. It was not until the 1980s, when he was already in his eighties, that he finally received recognition, was bestowed several awards, and saw his complete works published. There are four works in which he deals with the subject of homosexuality: Heraclés: sobre una manera de ser, an essay with his reflections on homoeroticism, written in 1955 and which took 20 years to be published in Spain. Its title refers to the Greek hero Hercules. Los arcángeles: parábola, in which he recalls experiences with other men. Tobeyo o Del amor: homenaje a México, in which he writes about the person he falls in love with during his Mexican exile. And finally, the novel Valentín: homenaje a William Shakespeare, in which he tells the story of a mature theater director who falls in love with a young actor. It has been adapted for theater and film by Juan Luis Iborra, in 1983 and 2002 respectively. According to Martínez Expósito (2011):

Other gay poets of the time included many members of the , such as , , Pablo García Baena, Julio Aumente, and . Younger poets Francisco Brines and Jaime Gil de Biedma were also gay. The latter, despite his rather brief poetic work, had a major influence on the Spanish poetry of his time and later. Professor referred to him as [el] «padre espiritual» de la poesía española posmoderna.  Gil de Biedma's poetry is characterized by its realist and ironic tone, as well as its discretion. Homoeroticism is a recurrent theme, but it is usually treated in an ambiguous and veiled manner. Thanks to the publication of his correspondence, he consciously avoided the apology of homosexuality and, except for Constantine P. Cavafy and Luis Cernuda, he was wary of openly homosexual poetry. Thus, in a letter to publisher , he said:

Gil de Biedma's diaries are much more explicit than his poetry. They were published during the author's lifetime but only after having cut the most risqué passages. They were only published in full after his death.

With regards to Brines, homosexuality is a recurrent theme in his poems, always as a natural manifestation of love (as opposed to the overall social stigma or its ties to what is criminal or sinful). According to literary critic :

After the Francoist dictatorship

After Franco's death and the arrival of democracy in Spain for a second time (the first time was during the Second Republic), there was greater freedom in the publishing world and a resurfacing of the theme of homosexuality (although society was still fundamentally sexist and homophobic during those years of the Transition). As late as 1981, Íñigo Cavero, the of the Union of the Democratic Centre, was retaliating against a radio program on Radio Nacional de España that had discussed the issue of homosexuality.

Oddly enough, despite the political activism waged by some groups during the 1970s, literature in the 1980s barely dealt with these issues. The social invisibility of homosexuals during the Francoist regime and the lack of Spanish-language examples in gay literature meant that new authors (in the case of those who intended to engage in "high culture") took as their models such figures as Oscar Wilde, Jean Genet, Marcel Proust, Arthur Rimbaud, or the Comte de Lautréamont. Those authors who intended to produce more commercial works set their sights on the world of mass culture, with Hollywood cinema being especially important for them.

Among the authors whose success came at the end of the dictatorship or with the Transition, those who stand out include Juan Goytisolo (the most influential outside Spain and the one who continues the tradition of Jean Genet's poètes maudits with notable works such as Coto vedado and Carajicomedia), (Ante el espejo, Chicos, Divino, Oro y locura sobre Baviera, and El mal mundo), Antonio Gala, and Terenci Moix, publicly known for their frequent appearances on television and for being some of the first to publicly come out as gay in the late 1970s.