The U.S. Supreme Court on Monday overturned a ruling by the N.C. Supreme Court that prevented sex offenders from using social media.

In Packingham v. North Carolina, a convicted sex offender was arrested for using Facebook. The man, Lester Packingham, claimed a violation of his First Amendment rights.

In the court’s opinion, social media websites are an essential forum in the digital world, and a law preventing access for criminals excluded them from a principal means of communication.

“By prohibiting sex offenders from using those websites, North Carolina with one broad stroke bars access to what for many are the principal sources for knowing current events, checking ads for employment, speaking and listening in the modern public square, and otherwise exploring the vast realms of human thought and knowledge,” wrote Justice Anthony Kennedy in the 5-3 decision.

Justices Ginsberg, Breyer, Sotomayor, and Kagan supported Kennedy. Justice Samuel Alito wrote a concurring opinion that agreed with the more liberal justices on their judgment, but not on their reasoning. Conservative-leaning justices Roberts and Thomas sided with Alito. Justice Neil Gorsuch did not participate in the case.

The court pressed that limitations on a sex offender’s navigation of the internet had to prevent unlawful activity, such as contact of a minor, but that reasoning could not prevent its lawful use.

“It is unsettling to suggest that only a limited set of websites can be used even by persons who have completed their sentences,” the opinion stated. “Even convicted criminals — and in some instances especially convicted criminals — might receive legitimate benefits from those means for access to the world of ideas, in particular if they seek to reform and to pursue lawful and rewarding lives.”

The state court previously held that the law was a “limitation on conduct,” rather than a free speech violation, and claimed the government had an interest in “forestalling the illicit lurking and contact” of registered sex offenders and potential victims.

The opinion compared the North Carolina law to one overturned in a previous case involving a wide-ranging restriction on speech at Los Angeles International Airport. Both restrictions were considered overbroad and “an impermissible burden” under the First Amendment.

In his concurring opinion, Justice Alito took issue with the court’s equivalence of social media and public streets and parks.

“Cyberspace is different from the physical world, and if it is true, as the Court believes, that ‘we cannot appreciate yet’ the ‘full dimensions and vast potential’ of ‘the Cyber Age,’ we should proceed circumspectly, taking one step at a time,” Alito cautioned.

Packingham was convicted of indecent liberties with a minor in 2002, when he was a 21-year-old college student. Authorities were alerted to him in 2010 after he made a Facebook post thanking God for the dismissal of a parking ticket. The court’s opinion notes that more than 1,000 people have been prosecuted under the North Carolina law.