The US Supreme Court ruled 7 to 2 in favor of Colorado baker Jack Phillips, who refused to bake a cake for a same-sex couple's wedding.

The Court found that Phillips did break Colorado's anti-discrimination law by refusing to bake the cake, but also said the Colorado Civil Rights Commission's handling of the case showed hostility towards religion.

The U.S. Supreme Court on Monday handed a narrow victory to a Christian baker from Colorado who refused for religious reasons to make a wedding cake for a gay couple.

The justices, in a 7-2 decision, faulted the Colorado Civil Rights Commission's handling of the claims brought against Jack Phillips, saying it had showed a hostility to religion. In doing so, the commission violated his religious rights under the First Amendment of the U.S. Constitution.

But the court did not issue a definitive ruling on the circumstances under which people can seek exemptions from anti-discrimination laws based on their religious views.

The commission had said Phillips violated the Colorado anti-discrimination law that bars businesses from refusing service based on race, sex, marital status or sexual orientation by rebuffing gay couple David Mullins and Charlie Craig in 2012.

Two of the court's four liberals, Stephen Breyer and Elena Kagan, joined the five conservative justices in the ruling authored by Justice Anthony Kennedy.

"The commission's hostility was inconsistent with the First Amendment's guarantee that our laws be applied in a manner that is neutral toward religion," Kennedy wrote, referring to the First Amendment of the U.S. Constitution.

"The outcome of cases like this in other circumstances must await further elaboration in the courts, all in the context of recognizing that these disputes must be resolved with tolerance, without undue disrespect to sincere religious beliefs, and without subjecting gay persons to indignities when they seek goods and services in an open market," Kennedy said.

Of the 50 states, 21 including Colorado have anti-discrimination laws protecting gay people.

The closely watched case before the Supreme Court, which in 2015 legalized same-sex marriage nationwide, pitted gay rights against religious liberty. President Donald Trump's administration intervened in the case in support of Phillips.