More than half of the countries in sub-Saharan Africa have anti-homosexuality laws, although others have moved towards legal tolerance, watchdogs say.
Twenty-eight out of 49 countries have laws penalising same-sex relationships, according to Neela Ghoshal, a Human Rights Watch (HRW) specialist in lesbian, gay, bisexual, and transgender rights.
The death penalty is on the books, under sharia, in Mauritania, Sudan and northern Nigeria, although there have been no known executions in recent times.
In southern Somalia, gay men are believed to have been put to death in territory ruled by the Al-Shabaab jihadist group.
However, Angola, Mozambique and Seychelles have scrapped anti-gay laws in recent years, and on Friday a High Court ruling in Nairobi will determine whether Kenya follows suit.
On the other hand, Chad and Uganda have introduced or toughened legislation.
Rights groups say many anti-gay laws date from the colonial area.
They represent a peril even in countries where they are not implemented, according to campaigners, as their existence on the statute books entrenches stigma and encourages harassment, they say.
Following is a snapshot of the legal situation in Africa, provided by AFP bureaux:
ANGOLA: Last month scrapped a notorious "vices against nature" provision in its penal code, and made the refusal to employ or provide services to someone on the grounds of their sexual orientation liable to a jail term of up to two years.
BOTSWANA: On March 15, the High Court will hear a case brought by campaign group Lesbians, Gays and Bisexuals of Botswana challenging the constitutionality of a law punishing same-sex conduct.
CHAD: Approved a law in May 2017 to punish "same-sex sexual relations" with between three months' and two years' jail and a fine ranging from 50.000 to 500.000 FCFA (76 to 760 euros, $85 to $850).
GABON: The first gay traditional wedding was conducted in 2013 but the couple was immediately arrested following an outcry. The pair was released and the marriage overturned on technical grounds.
LESOTHO: In 2012, approved a penal code which scrapped a common-law regime under which sodomy had been criminalised. Initiated a process in 2016 to decriminalise same-sex marriage, although the law is making little headway in parliament.
MALAWI: Debating the legal status of homosexuality. In 2012, the government ordered a moratorium on arrests and prosecutions of consensual homosexual adults. In 2016, the High Court suspended the moratorium pending a judicial review by the Constitutional Court.
MOZAMBIQUE: In 2015, swept away Portuguese colonial laws dating back to 1886 that punished anyone "who habitually engages in vices against nature." No known prosecutions under those laws occurred after Mozambique gained independence in 1975.
MALI: No anti-homosexuality law, but conservative Islamic groups last December successfully campaigned against a Dutch-funded schoolbook on sexual education, maintaining it promoted homosexuality.
NIGERIA: Law introduced in 2014 provides for up to 14 years' jail for same-sex cohabitation and any "public show of same-sex amorous relationship". In the north, sharia makes homosexuality punishable by death in theory.
SOUTH AFRICA: In 2006, South Africa became the sole African nation to allow gay marriage. The country has become a haven for African homosexuals who flee persecution at home or travel to the country to get married before returning home.
TANZANIA: A conviction for having "carnal knowledge of any person against the order of nature" can lead to 30 years' jail or more. Political rhetoric against homosexuality has increased since President John Magufuli was elected in 2015. Foreign gay rights activists have been expelled and last October, the governor of Dar es Salaam, the country's economic capital, threatened to arrest homosexuals.
UGANDA: Defying Western criticism, President Yoweri Museveni in February 2014 signed an Anti-Homosexual Bill that hiked the penalty for same-sex relations from seven years to life, and extended punishments to people found guilty of "promoting" homosexuality. However, it was annulled by court six months later, in what activists hailed as a victory.
ZAMBIA: Homosexuality is widely reviled and same-sex relationships can draw sentences of between a year and 14 years' jail. Earlier this month, TV regulators ordered a new locally-produced reality show, "Lusaka Hustle," to be taken off the air on the grounds that it promoted a gay lifestyle.