CHICAGO — United Airlines got slapped around on social media Sunday when it barred a pair of teen girls in leggings from boarding a flight, but the reality is airlines still have dress codes, at least for some passengers.

Enforcing them can be tricky, though, as United Airlines found out when a gate agent didn’t let the two girls get on a Sunday morning flight from Denver to Minneapolis.

When a traveler who saw the incident criticized the airline’s move on Twitter, United responded by tweeting it had the right to refuse passengers who are “not properly clothed,” citing its passenger contract. The contract says the Chicago-based airline can bar passengers who are barefoot or not properly clothed for the safety of all passengers and crew members, but doesn’t specify what proper attire entails.

Complaints poured in on social media, with many users calling the policy sexist and criticizing the airline’s decision to “police” passengers’ attire, noting one girl’s father reportedly was allowed to board in shorts.

United later said the passengers were flying on passes that let employees and their friends or family fly free or at heavily discounted rates. The airline has a separate dress code for employees and pass riders, who are seen as representing the airline when flying, United said in a blog post.

“To our regular customers, your leggings are welcome,” United wrote.

The explanation and reassurance did little to head off the criticism, including an online petition urging the airline to change the policy that had garnered 500 signatures Monday afternoon and tweets from celebrities.

“I suggest u consider updating ur rules 4 friends & fam as they seem to apply mostly 2 females & are outdated,” comedian Sarah Silverman tweeted at United Sunday.

United pushed back against the idea that a leggings ban is sexist. The airline’s policy calls out specific apparel items to try to limit the extent to which the definition of “appropriate” is up to individual gate agents’ discretion, said United spokesman Jonathan Guerin.

“We don’t want to put them in a position to make judgment calls about people’s attire,” he said.

United pass travelers also can’t fly in flip flops, slippers and clothing with holes or tears. Failing to cover your midriff or undergarments can keep you grounded too.

Most airlines require the attire of employees and their guests to fit in with or be slightly nicer than what regular passengers wear, said Brian Sumers, airline business reporter at travel industry website Skift. That might have meant a jacket and tie 20 years ago, but as customers have opted for more comfortable attire, airlines have let pass riders dress down too, Sumers said.

Delta Air Lines doesn’t have an item-specific dress code and encourages employees to use their best judgment, but a pass travel etiquette guide warns against swimwear, pajamas and any unclean, revealing or lewd garments.

American Airlines may deny boarding to employees and their guests if they are wearing torn, dirty or frayed clothing, overly revealing clothing, swimwear or sleepwear that is “distracting or offensive to others,” and vulgar apparel with offensive words or images. In first or business class, American also deems shorts, flip-flops, jogging suits, athletic gear and baseball-style caps inappropriate, according to an employee travel guide.

It’s unclear how those rules would apply to leggings, which have become a staple wardrobe item for many women as the athleisure trend has boomed.

So why don’t we hear more about airline dress codes? It’s extremely rare for airlines to turn away paying customers over wardrobe issues, Sumers said. And most employees are aware of the rules and consider the perk worth the extra strings, Sumers said.

“It’s one of the main reasons people like working in the airline industry and for most, the fact that you have to dress sort of presentably is not that big a deal,” he said.

United said the gate agent who turned the girls away handled the situation appropriately, as did the girls, who were understanding about the incident, according to Guerin.

But United’s Guerin said the airline shouldn’t have responded to tweets about the incidents before getting all the facts straight. “That’s something we learn from, for sure.”