The Supreme Court on Monday struck down part of a federal law blocking trademarks for names or logos bearing "immoral" or "scandalous" images -- including profanity and sexual imagery.

The justices said in a unanimous ruling that the law violated the constitutional rights of designer Erik Brunetti. Registration for his clothing brand "FUCT" (pronounced as the individual letters F-U-C-T) had been denied by a federal tribunal.

SUPREME COURT REJECTS EARLY CHALLENGE TO TRUMP STEEL TARIFFS

"The statute, on its face, distinguishes between two opposed sets of ideas: those aligned with conventional moral standards and those hostile to them; those inducing societal nods of approval and those provoking offense and condemnation," Justice Elena Kagan wrote in the court's opinion.

Section 2a of the Lanham Act currently excludes "immoral, deceptive, or scandalous matter; or matter which may disparage or falsely suggest a connection with persons, living or dead, institutions, beliefs, or national symbols, or bring them into contempt, or disrepute."

When applying the prohibition, the Patent and Trademark Office looks at whether the public would find the trademark in question "shocking to the sense of truth, decency, or propriety." An appeals board found that "FUCT" was "highly offensive" and "vulgar," according to court documents.

But because the law "disfavors certain ideas," Kagan wrote, it violates the First Amendment. To illustrate this further, Kagan cited examples of approved and rejected trademarks related to drugs. Those seeming to endorse drug use, such as "YOU CAN'T SPELL HEALTHCARE WITHOUT THC" and "MARIJUANA COLA," were shot down. Anti-drug marks including "D.A.R.E. TO RESIST DRUGS AND VIOLENCE" and "SAY NO TO DRUGS---REALITY IS THE BEST TRIP IN LIFE" were approved.

SUPREME COURT THROWS OUT MURDER CONVICTION OF BLACK INMATE AS KAVANAUGH, GORSUCH SPLIT AGAIN

In a concurring opinion, Justice Samuel Alito recognized that the government could legally bar a trademark like "FUCT" if it employed a narrower restriction, but that was not the case here. The existing law went too far by discriminating based on viewpoint, he argued.

"Viewpoint discrimination is poison to a free society," Alito wrote, saying that the court must "remain firm" on this issue, during "a time when free speech is under attack."

The outcome of the case, Iancu v. Brunetti, mirrors a 2017 decision where the high court struck down a similar ban on "derogatory" marks that may affect races, cultures, beliefs, or national symbols.

Fox News' Shannon Bream and Bill Mears contributed to this report.