A federal appeals court on Wednesday affirmed a Maryland beach town’s right to ban women from topless sunbathing.

A three-judge panel of the 4th U.S. Circuit Court of Appeals in Richmond ruled unanimously that Ocean City’s law, which allows men to be topless but not women, is constitutional.

Ocean City passed its law in 2017 after one of the plaintiffs in the case, Chelsea Eline, contacted Ocean City police and asserted a right to go topless.

MARYLAND AUNT OF CHILDREN FOUND DEAD IN CAR DURING TRAFFIC STOP DROVE AROUND WITH THEM FOR MONTHS

The panel’s ruling notes that courts across the country have upheld laws banning women from topless sunbathing on public beaches. While the law imposes a restriction on women that is not imposed on men, Judge A. Marvin Quattlebaum Jr. wrote that Ocean City’s elected leaders are within their rights to enact laws that protect public sensibilities.

People enjoy the boardwalk during the Memorial Day holiday weekend amid the coronavirus pandemic on May 23, 2020 in Ocean City, Maryland. (Photo by ALEX EDELMAN/AFP via Getty Images)

People enjoy the boardwalk during the Memorial Day holiday weekend amid the coronavirus pandemic on May 23, 2020 in Ocean City, Maryland. (Photo by ALEX EDELMAN/AFP via Getty Images)

"The judicial legacy of justifying laws on the basis of the perceived moral sensibilities of the public is far from spotless. Some government action that we now rightly view as unconstitutional, if not immoral, has been justified on that basis. Even so, in this situation, protecting public sensibilities serves an important basis for government action," Quattlebaum wrote.

Town leaders said they received calls and letters overwhelmingly supporting the ban.

In a concurring opinion, Chief Judge Roger Gregory wrote that U.S. Supreme Court precedent requires upholding the ban. But he suggested the court should reconsider the issue.

"At first glance, Ocean City’s ordinance seems innocuous enough. ... But we must take care not to let our analysis be confined by the limits of our social lens," Gregory wrote. "Suppose the ordinance defined nudity to include public exposure of a woman’s hair, neck, shoulders, or ankles. Would that law not run afoul of the Equal Protection Clause?"

CLICK HERE TO GET THE FOX NEWS APP

A town spokesman and an attorney for the plaintiffs did not immediately return calls seeking comment Wednesday afternoon.