LOS ANGELES - For decades, toy makers believed the industry gospel: Boys want to build things; girls want to play princess.

But now, female CEOs are leading huge corporations, including Yahoo Inc. and General Motors Corp., and more women are becoming engineers and mathematicians. Meanwhile, toy companies are realizing that girls want to build bridges and wire circuits.

Parents, too, are demanding playthings that nurture a love of science and math in their daughters, driven in part by nationwide hand-wringing over a lack of interest in STEM careers (short for science, technology, engineering and math).

As a result, construction toys, bolstered by demand from girls, are a bright spot in the $22-billion industry, which has seen other categories stagnate or decline.

Eager to make up for lost time, Mattel Inc. in April acquired Mega Brands, known for its construction sets. Giant toy maker Lego has retooled its classic building kits with a splash of purple and themes such as pet salon and beauty shop. Upstart toy companies are designing girl-friendly toys that combine fun with scientific principles.

“It’s baffling that it took this long for toy makers to get on board,” said Jaime Katz, an equity analyst at Morningstar. “If you aren’t catering to the girls’ side you are leaving half of the market on the table.”

Although building sets were flat last year, the category climbed 22% to $2 billion in 2012, up from $1.6 billion in 2011, according to NPD Group. Over those two years, action figures dropped by 2.1% and plush toys slid by 5.4%.

“This is an untapped opportunity,” said Michael Swartz, research analyst at SunTrust Robinson Humphrey. “The hot product begets copycats.”

Toy makers have challenged traditional gender roles in the past - especially during the feminist movement in the 1960s and 1970s.

Then manufacturers started moving away from gender-free toys and sharpened their focus on targeting girls and boys separately. The reason: Toys aimed at one gender were better sellers.

But after years ignoring the space, toy companies have been paying close attention to how girls like to build.

Lego spent four years researching the female market after realizing that girls weren’t demanding its toys as much as boys were, said Michael McNally, senior director of brand relations for Lego Systems.

The Danish company debuted its Friends line in 2012 with girls top of mind: The sets have a bright color palette with lots of purple, and come with more human-like figures.

“It changed the perception that Lego is for boys,” McNally said. “It’s been a gateway for girls.”

Lego’s focus has paid off handsomely. Prior to Friends, only about 10% of Lego sets were bought for girls. Within eight months of the line’s launch, that grew to 25%, McNally said.

“We have only begun to scratch the surface,” he said.

To win over girls, toy makers say they have to walk a careful line: Avoid pandering by “pinking and shrinking” boy toys but also design a product that is entertaining enough to woo customers. While boys are often satisfied just by building something cool-looking, girls want more narrative and storytelling in their construction toys, experts say.

The growing popularity of construction toys for girls also reflects a shift in family dynamics. Parents are increasingly more open to toys that cross traditional gender stereotypes, and dads are taking a bigger share of child-care duties.

“Parents are telling kids it’s OK to be different,” said analyst Swartz, who pointed to Hasbro’s introducing an Easy Bake Oven with a color scheme more appealing to boys.

“Little boys are not berated by their fathers for playing with those kinds of toys,” he said. “Parents are telling their girls that you don’t have to be constrained to a life at home cooking and cleaning.”

Toys R Us is seeing more fathers buy building playthings for their daughters, said Richard Barry, the company’s chief merchandising officer.

“There is absolutely a pattern of dads buying and building Legos with their daughters,” he said. “It introduces a play pattern that maybe girls would like.”

Some of the biggest innovators have been women with science backgrounds who are tired of seeing fashion dolls and necklace-making kits dominate the toy store.

Chen and Brooks of Roominate met as engineering grad students at Stanford University. Another Stanford grad with an engineering degree, Debbie Sterling, founded GoldieBlox, one of the most talked-about toy start-ups this holiday season.

Sterling said she got into construction toys after seeing the lack of female engineering majors in school. Her goal: to create toys that nurture an early interest in science and math in girls, the way that building sets have done for boys.

“Girls are just inundated with toys and characters that don’t motivate or encourage anything beyond showing them it’s important to be beautiful,” she said. “Most in the toy industry told me the idea would never go mainstream and in order to appeal to girls, it had to be sparkly with ponies.”

GoldieBlox has been working to add more diverse characters. One of Goldie’s new buddies, an African American girl named Ruby, is a programmer and social butterfly.

“She really shatters the perception that all coders are guys in hoodies who don’t shower and have no friends,” Sterling said.