The Supreme Court ruled on Friday that state bans on marriage among same-sex couples are unconstitutional, a historic decision that caps off a rapid change in public opinion on gay marriage.

In a 5-4 decision, the court decided that states can no longer limit the right to marry to heterosexual couples. Before the decision, 13 states banned same-sex marriage, mostly in the Midwest and South.

“The court now holds that same-sex couples may exercise the fundamental right to marry. No longer may this liberty be denied to them,” Justice Anthony Kennedy wrote in the majority opinion.

Justices Ruth Bader Ginsburg, Stephen G. Breyer, Sonia Sotomayor and Elena Kagan joined Kennedy in the majority opinion, while Chief Justice John G. Robert Jr. and Justices Antonin Scalia, Clarence Thomas and Samuel A. Alito Jr. dissented.

State-by-state legalization of same-sex marriage has spread rapidly around the U.S. in the last few years. Eleven years ago, Massachusetts became the first state to legally recognize same-sex marriage.

As of earlier this week, same-sex couples could marry in 37 states and the District of Columbia. Recent surveys by the Public Religion Research Institute showed that over half of the states expressed majority support for same-sex marriage.

You might also like:

-The one Supreme Court paragraph on love that gay marriage supporters will never forget

-A double rainbow above the White House last week was seen as a symbol of progress

-Justice Scalia suggests asking a hippie about gay marriage. Here’s how to find one near you