(covers information from several alternate timelines)
In many cultures, sexuality, or having a sex life, was the physiological or emotional drive responsible for physical attachments stemming either from a biological or societal need to bond with a mate. This adaptation facilitated sexual reproduction as well as often deep-seated needs for satisfaction and physical and emotional intimacy.
Many species had complex interactions (see mating rituals) and communications involved in approving or rejecting a potential mate. Chemical adaptations such as attractive pheromones or biochemical bonds were also evolved by some lifeforms, such as Orions and Varro. (ENT: "Bound"; VOY: "The Disease", "Someone to Watch Over Me")
Deltans were also known to project a strong sexual presence even without physical contact, which might have included pheromones and some subconscious telepathic elements. The effects were sufficiently strong as to influence other species. (Star Trek: The Motion Picture)
Soong-type androids were incorporated with a sexuality program, and considered to be "fully functional" in terms of sexuality and were programmed with multiple sexual techniques. (TNG: "The Naked Now", "Inheritance"; Star Trek: First Contact)
Sexual diversity Edit
In many species, sexual relationships between different sexes were commonplace, most often between male and female mates. Examples for such relationships include James T. Kirk and Carol Marcus, Kira Nerys and Bareil Antos, and Agnes Jurati and Cristóbal Rios. (DS9: "Shadowplay"; PIC: "The Impossible Box"; Star Trek II: The Wrath of Khan)
Some species had sexual relationships between more than two sexes, such as Species 8472, Vissians, and Rigellians. (VOY: "Someone to Watch Over Me"; ENT: "Cogenitor"). Other species were genderless or hermaphroditic, such as the J'naii or the Tholians, and therefore most often had sexual relationships without regards for their partner's sex. (TNG: "The Outcast"; ENT: "In a Mirror, Darkly")
Same-sex sexual relationships occurred in many species, including Humans, Bajorans, and Trill. Some individuals, such as Hugh Culber and Paul Stamets, preferred same-sex relationships exclusively. Others, such as Jadzia Dax, had sexual encounters and relationships with male and female partners. (DS9: "Rejoined", "The Emperor's New Cloak"; DIS: "Choose Your Pain", "Through the Valley of Shadows", "The Red Angel").
Individuals from the mirror universe were also known to enjoy sexual encounters regardless of their partner's sex. Emperor Philippa Georgiou took an interest in male and female partners, as did Intendant Kira. (DS9: "The Emperor's New Cloak"; DIS: "Will You Take My Hand?") According to Georgiou, Stamets of her universe was also pansexual. (DIS: "The Red Angel")
Among the space-faring civilizations of the Federation, interspecies sexual relationships were commonplace. Examples for such relationships include Nyota Uhura and Spock of the alternate reality, Jadzia Dax and Worf, as well as Tom Paris and B'Elanna Torres. (DS9: "Looking for par'Mach in All the Wrong Places"; VOY: "Day of Honor", "Scientific Method"; Star Trek) These sexual encounters sometimes resulted in hybrid children, although medical assistance could be needed to assure safe pregnancies. (DS9: "Tears of the Prophets"; VOY: "Deadlock", "Lineage"; ENT: "Demons") Even without the intent to reproduce, sexual encounters between different species could sometimes have unforeseen consequences. (VOY: "The Disease"; ENT: "Unexpected")
Sexual taboos were also present in some cultures. The J'naii were known to enforce laws prohibiting the occurrence of sexual acts considered deviant by the majority of the population. The Trill forbade the act of reassociation between new hosts of Trill symbionts who were previously in a relationship. The Varro did not allow sexual encounters with other species, in part because of their unique biochemistry. (TNG: "The Outcast"; DS9: "Rejoined"; VOY: "The Disease"). In other species, sexual encounters were guided by strict cultural norms, such as the Vulcan pon farr. (TOS: "Amok Time"; VOY: "Blood Fever").
Types of sexual relationships Edit
Sexual encounters between individuals could be spontaneous and one-time occurrences, occasional affairs, or they could lead to long-lasting relationships. The legal recognition of sexual and romantic relationships was usually referred to as marriage. (TOS: "The Conscience of the King"; TNG: "The Price", "Data's Day"; DS9: "Let He Who Is Without Sin...", "You Are Cordially Invited", "'Til Death Do Us Part"; VOY: "Someone to Watch Over Me", "The Disease", "Drive"; DIS: "Through the Valley of Shadows"; Star Trek Nemesis)
Sexual activities and relationships were often shared intimately between two partners, but they could also involve more than two people. (DIS: "Will You Take My Hand?") In some species and cultures, such as Denobulans and Rakhari, polygamous relationships were the norm. (DS9: "Vortex"; ENT: "Dear Doctor", "Stigma")
At times, sexual activities were used for purposes beyond reproduction, recreation and intimacy. These cases included creating distractions for various purposes, psychological assessments of others, and even intelligence operations. (ENT: "Bound"; DIS: "Lethe"; PIC: "Maps and Legends"; Star Trek V: The Final Frontier)
Sexual encounters did not only occur between real people but also in simulations, daydreams and holographic programs. Although these situations were considered embarrassing or even repulsive by some, they were also seen as an acceptable outlet for sexual desires, especially in cases of long isolation. (TNG: "Hollow Pursuits"; DS9: "The Forsaken"; VOY: "Fair Haven", "Tinker Tenor Doctor Spy", "Body and Soul")
Forceful sexual encounters occurred in some species, often referred to as rape. These were considered severe and traumatic crimes by many cultures, including the Federation, the Bajorans, and the Tanugans. Rape could occur under individual circumstances, but also as a systemic issue during times of crises, such as the Occupation of Bajor. (TOS: "The Enemy Within", "The Return of the Archons"; TNG: "A Matter of Perspective", "Legacy"; DS9: "Duet", "Wrongs Darker Than Death or Night"; DIS: "Into the Forest I Go") Rape was not limited to physical violations but could also be induced telepathically. (TNG: "Violations"; Star Trek Nemesis)
Background information Edit
Depiction of sexuality in Star TrekEdit
Marina Sirtis has noted that the depiction of Deanna Troi's sex life on Star Trek: The Next Generation had been liberal and nonjudgmental at a time, when women were rarely shown to be sexual on television shows. She also admired that Troi was allowed to be sexually active, feminine, and competent at the same time.  
A cut line in "Paradise" had the self-proclaimed philosopher Alixus claim that she had a lot to say about sexuality, which she believed would shock someone as repressed as Benjamin Sisko seemed to her. This apparently included the acceptability of sexual procurement. 
Non-heterosexual characters in Star TrekEdit
George Takei recalled that during the production of Star Trek: The Original Series he had asked creator Gene Roddenberry why there were no gay or lesbian characters in the series. According to Takei, "He said 'I'm treading a fine tight wire here. I'm dealing with issues of the time. I'm dealing with the civil rights movement, the Vietnam War, the Cold War, and I need to be able to make that statement by staying on the air.' He said, 'If I dealt with that issue I wouldn't be able to deal with any issue because I would be canceled.'" 
During the first season of Star Trek: The Next Generation, writer David Gerrold prepared a script, "Blood and Fire", an allegory on society's fear of AIDS. Gerrold recalled, "There were two characters who were not very important to the story, but they were the kind of background characters you need. At one point Riker says to one of them, 'How long have you two been together?' That was it. The guy replies, 'Since the Academy.' That's it. That's all you need to know about their relationship. If you were a kid, you'd think they were just good buddies. If you were an adult, you'd get it. But I turned in the script and that's when the excrement hit the rotating blades of the electric air circulation device. There was a flurry of memos, pro and con. One memo said, 'We're going to be on at four in the afternoon in some places and we're going to get angry letters from mommies.' My response was, 'If we get people writing letters, it shows they're involved in the show, and that's exactly what we want. We want them engaged, and a little controversy will be great for us.' And I said, 'Gene [Roddenberry] made a promise to the fans. If not here, where? If not now, when?' But the episode got shelved anyway and that's when I knew I wasn't going to be allowed to write the very best stories we should be writing. The original show was about taking chances. If we weren't going to take chances, we weren't doing Star Trek. So I let my contract expire and I went off to do [...] other things." 
First portrayals of homosexuality in the 1990s and 2000sEdit
By the fifth season of The Next Generation, the omission of non-heterosexual characters was increasingly controversial. The show became the subject of a number of letter-writing campaigns demanding that such characters were included. (Star Trek: The Next Generation Companion, 2nd ed., p. 194) Michael Piller remembered, "Roddenberry had been barraged by letters and had discussed with us before his death the possibility of having two men hold hands in some scene." However, neither Piller nor Rick Berman felt that this was an appropriate way to handle the matter. (Captains' Logs: The Unauthorized Complete Trek Voyages, pp. 240-241)
Instead, the producers of TNG decided to address homosexuality in an allegorical manner. The 1992 episode "The Outcast" featured a romance between the male character William T. Riker and Soren, a member of an androgynous species who was persecuted for her "deviant" expression of femaleness. All of the J'naii, including Soren, were played by female actors. Berman commented that "having Riker engaged in passionate kisses with a male actor might have been a little unpalatable to viewers." (San Jose Mercury News, Grapevine, March 14, 1992) Jonathan Frakes criticized this decision. "I didn't think they were gutsy enough to take it where they should have. Soren should have been more obviously male. We've gotten a lot of mail on this episode, but I'm not sure it was as good as it could have been – if they were trying to do what they call a gay episode." (Captains' Logs: The Unauthorized Complete Trek Voyages, p. 240) Berman noted, "We thought we had made a very positive statement about sexual prejudice in a distinctively Star Trek way, but we still got letters from those who thought it was just our way of 'washing our hands' of the homosexual situation." (Star Trek: The Next Generation Companion, 2nd ed., p. 194)
Actor Andrew Robinson saw his recurring character Elim Garak on Star Trek: Deep Space Nine as having an ambiguous sexuality. In an interview after the series concluded he commented, "He's not gay, he's not straight, it's a non-issue for him. Basically his sexuality is inclusive." However, Robinson noted that this aspect was not developed. He speculated this was for several reasons. "One is that Americans really are very nervous about sexual ambiguity. Also, this is a family show, they have to keep it on the 'straight and narrow', so then I backed off from it […] For the most part, the writers supported the character beautifully, but in that area they just made a choice they didn't want to go there, and if they don't want to go there I can't, because the writing doesn't support it." 
Intendant Kira Nerys from the mirror universe was revealed to be bisexual in the Star Trek: Deep Space Nine episode "Through the Looking Glass". Several other inhabitants of that universe were also shown to be lesbian or bisexual in subsequent episodes. Actress Nana Visitor commented, "I never intended for the Intendant to be bisexual. I think that was an assumption that everyone, including the writers, made after the character fell for Kira in ['Crossover']. But that had been total narcissism on her part. It had nothing to do with sexuality. I never liked that people took her for bisexual because she's an evil character. There are so few gay characters on TV, and we really don't need an evil one." (Star Trek: Deep Space Nine Companion, p. 644) Author Christopher L. Bennett was uncomfortable with the portrayal. On an episode review by fellow author Keith R.A. DeCandido, Bennett commented, "It plays too much into the 'sex = evil' stereotype, and particularly into the 'gay/bi = evil' stereotype. It wouldn’t have been so bad if they’d established that our Kira was at least potentially bisexual herself, but they instead played 'good' Kira as strictly hetero while 'bad' Kira would screw anything that moved, and that has some unpleasant implications." 
Ronald D. Moore stated during the production of Season 6 of Star Trek: Deep Space Nine that the show was not interested in stories about homosexuality, or revealing any main character as bi or gay, because it would not really be an issue to them, and so "exploring" it did not hold much promise. He did not disagree that maybe the show should do stories in this vein, but felt that he was more passionate about other issues and therefore should write about that. (AOL chat, 1997)
Regular portrayals of queer charactersEdit
It was not until 2016 that a regular character was portrayed and marketed as openly gay. In that year, Star Trek Beyond was released which implied that Hikaru Sulu of the alternate reality had a husband, Ben.
The idea to portray Sulu as gay was in part intended to pay homage to actor George Takei, who played Sulu on Star Trek: The Original Series. Takei came out publicly as gay in 2005 and had been a vocal advocate for LGBTQ rights ever since. Although Takei was ultimately flattered by the decision, he also criticized it, as he himself had portrayed Sulu as straight and also felt that it was neither true to Gene Roddenberry's original vision, nor the circumstances under which the character was created. Takei would have favored the inclusion of a new regular gay character.   
In 2017, Star Trek: Discovery premiered, which portrayed the relationship of series regular Paul Stamets with the recurring character of Hugh Culber. In relation to Stamets, series creator Bryan Fuller commented, "Star Trek started with a wonderful expression of diversity in its cast... we're continuing that tradition." 
In 2019, the regular character Jett Reno was introduced on Star Trek: Discovery as a widower who had lost her wife during the Federation-Klingon War. In the same year, Stamets also became the first Star Trek character to describe himself in dialogue as gay in "The Red Angel". Pansexuality was first mentioned in the same scene.
The 2020 season 1 finale of Star Trek: Picard, "Et in Arcadia Ego, Part 2", depicted Seven of Nine and Raffi Musiker as holding hands in their final scene. According to showrunner Michael Chabon, the two characters are exploring a romantic relationship.  Although Seven and Raffi did not have many scenes together during the season, the romance was included at the behest of Jeri Ryan, Michelle Hurd, and the writers, who felt a connection between the characters during a previous shared moment in "Stardust City Rag".