Parents with religious objections to storybooks with LGBTQ+ themes may withdraw their children from public schools when the books are discussed, the Supreme Court ruled Friday.

Ruling in a case brought by Maryland parents who objected to books with gay and transgender characters, Justice Samuel A. Alito Jr. closely analyzed the messages the books conveyed, reproducing color images from them in an appendix to his opinion, and noted that they were written for young readers.

But the logic of Alito’s majority opinion in the 6-3 decision seemed to sweep quite broadly, allowing parents with religious objections to demand that their children not be instructed about gay and transgender themes or other topics.

Indeed, some legal scholars said the ruling would have broad consequences for the ability of public schools to manage their curricula. In earlier cases, parents unsuccessfully challenged storybooks about wizards and giants along with course materials on yoga, evolution and women working outside the home. Under Alito’s reasoning, legal experts said, those lawsuits might now succeed.

Justice Sonia Sotomayor announced her dissent from the bench, a rare move and a sign of profound disagreement.

In her written dissent, joined by Justices Elena Kagan and Ketanji Brown Jackson, she wrote that public schools “offer to children of all faiths and backgrounds an education and an opportunity to practice living in our multicultural society.”

“That experience,” she added, “is critical to our nation’s civic vitality. Yet it will become a mere memory if children must be insulated from exposure to ideas and concepts that may conflict with their parents’ religious beliefs.”

Justin Driver, a law professor at Yale, said the decision was deeply problematic.

“This decision succeeds in opening Pandora’s box in countless classrooms located in our nation’s public schools,” he said. “It unwisely grants parents and students the authority to, in effect, veto individual school lessons and assignments, thereby wreaking educational havoc.”

A lawyer for the parents, Eric Baxter of the Becket Fund for Religious Liberty, welcomed the decision.

“This is a historic victory for parental rights in Maryland and across America,” he said. “Kids shouldn’t be forced into conversations about drag queens, pride parades or gender transitions without their parents’ permission.”

The decision extended a winning streak for claims of religious freedom at the court, gains that have often come at the expense of other values — notably, gay rights.

The new case concerned a curriculum adopted in 2022 for prekindergarten through the fifth grade by the Montgomery County Public Schools, Maryland’s largest school system.

The storybooks included “Pride Puppy,” an alphabet primer about a family whose puppy gets lost at a Pride parade; “Love, Violet,” about a girl who develops a crush on her female classmate; “Born Ready,” about a transgender boy; and “Uncle Bobby’s Wedding,” about a same-sex union.

At first, the school system gave parents notice when the storybooks were to be discussed, along with the opportunity to have their children excused. But school administrators soon eliminated the advance notice and opt-out policy, saying it was hard to administer, led to absenteeism and risked “exposing students who believe the storybooks represent them and their families to social stigma and isolation.”

Parents of several faiths sued, saying the books violated the First Amendment’s protection of the free exercise of religion. The books, their complaint said, “promote one-sided transgender ideology, encourage gender transitioning and focus excessively on romantic infatuation.”

The parents said they did not seek to remove the books from school libraries and classrooms but only to shield their children from having to discuss them. (The school system has since withdrawn two of the seven books, including “Pride Puppy.” In court papers, officials said the books had been reevaluated under standard procedures but did not elaborate.)

Alito critiqued several of the books at issue in the case. About “Uncle Bobby’s Wedding,” for instance, he wrote, “It is significant that this book does not simply refer to same-sex marriage as an existing practice. Instead, it presents acceptance of same-sex marriage as a perspective that should be celebrated.”

Some Americans agree with that message, he wrote. “But other Americans wish to present a different moral message to their children,” he added. “And their ability to present that message is undermined when the exact opposite message is positively reinforced in the public school classroom at a very young age.”

Alito said the request in the case was a modest one. “What the parents seek here is not the right to micromanage the public school curriculum, but rather to have their children opt out of a particular educational requirement that burdens their well-established right” to direct their children’s religious upbringing.

Sotomayor drew a different conclusion, noting that there are more than 47 million public school students in the United States who adhere to range of religious beliefs.

“Against that backdrop, requiring schools to provide advance notice and the opportunity to opt out of every book, presentation or field trip where students might encounter materials that conflict with their parents’ religious beliefs will impose impossible administrative burdens on schools,” she wrote.

And objecting to what she called selective excerpts from “Uncle Bobby’s Wedding,” the appendix to her opinion reproduced the entire book.