News of a victory for same-sex marriage in Taiwan has some in China peering wistfully at the democratic island across a narrow strip of sea.

By afternoon Thursday, a day after Taiwan’s top court paved a path for gay marriage in two years, the hashtag #TaiwanGayMarriageLegalization had attracted some 11 million views on China’s Weibo social-media platform, with users posting rainbow flags, hearts and congratulations.

"We...