Thousands of Taiwanese have protested outside the legislature for and against a bill that could make it the first place in Asia to legalize same-sex marriage.

Organizers estimated that Thursday's protests attracted more than 20,000 people who carried placards, flew flags and chanted slogans as lawmakers deliberated the bill inside.

Both the ruling and major opposition parties support the measure, as do a majority of the public and President Tsai Ing-wen, Taiwan's first female head of state.

Opponents include religious groups and some conservative politicians.

Taiwan would join Canada, Colombia, Ireland, the United States and 16 other countries that have legalized same-sex marriage. But it would be a notable exception in Asia and the Middle East.