INDIANAPOLIS — An Indiana law that bans registered sex offenders from using Facebook and other social networking sites that can be accessed by children is unconstitutional, a federal appeals court ruled Wednesday.

The US Court of Appeals for the Seventh Circuit in Chicago overturned a federal judge’s decision upholding the law, saying the state was justified in trying to protect children but that the ‘‘blanket ban’’ went too far by restricting free speech.

The 2008 law ‘‘broadly prohibits substantial protected speech rather than specifically targeting the evil of improper communications to minors,’’ the judges wrote.

Advertisement

‘‘The goal of deterrence does not license the state to restrict far more speech than necessary to target the prospective harm,’’ they said.

The judges noted that the US Supreme Court has also struck down laws that restricted the constitutional right to freedom of expression, such as one that sought to ban leafleting on the premise that it would prevent littering.

The American Civil Liberties Union of Indiana filed the class-action suit on behalf of a man who served three years for child exploitation and other sex offenders who are restricted by the ban even though they are no longer on probation.

The ACLU applauded the decision.

Indiana Attorney General Greg Zoeller said his office would review the ruling before deciding on the next step.