WASHINGTON - The Supreme Court has struck down a Minnesota law that restricted what voters can wear to polls.

The justices ruled Thursday that the law violates the First Amendment. Still, the justices' 7-2 ruling suggested that some restrictions on what people can wear to vote are permissible.

The law was initially challenged by a voter temporarily turned away for wearing a Tea Party shirt and a "Please I.D. Me" button.

During oral arguments in February, state officials said the law had not been challenged until now.

Chief Justice John Roberts issued the court's opinion, calling the state's effort to make polling places less clamorous worthy. But "Minnesota has not supported its good intentions with a law capable of reasoned application," he said.

Justices Sonia Sotomayor and Stephen Breyer dissented, saying Minnesota's highest court should have an opportunity to weigh in first.

RELATED: SCOTUS to hear MN ban on voter dress code

Most states have laws restricting what voters can wear to cast their ballots, but Minnesota's law is one of the broadest. It bars voters from casting a ballot wearing clothing with the name of a candidate or political party or related to an issue on the ballot. Minnesota voters also can't wear clothing promoting a group with recognizable political views.

The state had defended its law as a reasonable restriction that keeps order at polling places and prevents voter intimidation.

The Supreme Court in 1992 upheld a state law establishing 100-foot, campaign-free buffer zones around polling places. That law and others generally apply to active electioneering, not passive wardrobes.

The Minnesota case raised troubling new questions. Can a state prohibit voters from wearing a "Make America Great Again" or "#MeToo" T-shirt? How about displaying the gay rights movement's rainbow flag, or "Parkland Strong" to support the Florida community shaken by February's school shooting?

And why would it be OK to herald First Amendment freedom of speech rights across one's chest, but not Second Amendment rights affecting firearms?

"The problem is that so many things have political connotations," Justice Samuel Alito said in February. "There are always going to be hard calls."

Justice Anthony Kennedy, on the other hand, wondered if the polling place should be a politics-free zone.

"Why should there be any speech there at all?" he said. "You're there to vote."