< PREVIOUS SLIDE SLIDE 1 of 5 NEXT SLIDE > A Lululemon store. © Lululemon

It took a few decades, but a shift toward casual wear and fitness, as well as a company called Lululemon, is changing what everyone wears.

The first pairs of yoga pants Lululemon sold in 1998 were a simple item for women to wear at the studio. They were a mix of nylon and Lycra—synthetic elastic fibers that provided the stretch and softness needed to manage all those sweat-inducing contortions during a lengthy session on the mat.

Yoga, first as an exercise and later as a cultural phenomenon (or cliché, depending on your cynicism), had yet to take hold. At the turn of the century, the pants filled a niche for yogis who were simply looking for a higher-end alternative to plain cotton leggings.

Two decades later, they’ve conquered the closet, even for people who never see the inside of a yoga studio. In 2014, teenagers began to prefer leggings over jeans. Then people started wearing athletic clothing (or athleisure, but it’s mostly just yoga pants) to run errands. Now they’re wearing yoga pants to the office. U.S. imports of women’s elastic knit pants last year surpassed those of jeans for the first time ever, according to the U.S. Census Bureau.

Fashion trends seesaw constantly, but rarely does an entire category shift. Over four decades, rubber-soled sneakers gave way to basketball shoes, which in turn fell to trainers. Boxer briefs didn’t exist 25 years ago—drawers were still filled with plain old briefs. But now the hybrid is America’s most popular men’s underwear. Yoga pants have similarly managed to plunge denim into an existential crisis, threatening Levi Strauss & Co. so deeply that it had to scramble to adapt. The company added stretch and contouring to its jeans while hoping to retain some of their rugged essence.

The popularity of yoga pants has, predictably, led to a flood of competitors as brands fill every market segment, from Old Navy’s $20 pants to Lucas Hugh’s $230 versions. Lululemon Athletica Inc., largely credited with bringing stretchy pants to the masses, has poured money into developing new fabrics to fend off rivals—a pack that now includes the world’s biggest athletics companies.

“Consumers expect a lot more,” said Sun Choe, chief product officer at Lululemon. “They’re washing their garments more and more, and from a quality standpoint, it needs to stand up. They’re expecting some versatility in their product. They expect to be able to wear that pant or tight to Whole Foods or brunch.”

Related video: Lululemon has more room to run, Cramer says (provided by CNBC)

Lululemon’s original fabric, Luon, with a high proportion of nylon microfiber as opposed to a more typical polyester blend, was trademarked in the U.S. in 2005. Many of its newer fabrics are branded and geared toward specific uses. Luxtreme is a moisture-wicking, four-way stretch fabric that’s meant to fit like a second skin. Nulux is a compression fabric meant for sweatier workouts. Silverescent is sold as Lululemon’s “stink-conquering technology,” using silver bonded to the surface of fibers to stop bacteria from reproducing. A T-shirt made from the material costs $68.

Leggings from market competitors use a similar strategy, promoting the versatile pants through branded fabric combinations. For Adidas, pants boast fabrics like its sweat-wicking Climalite material or the thermal-regulating Climacool and Climawarm to accommodate training conditions. Likewise, Nike’s Dri-Fit material keeps sweat at bay and trainers dry. Even Target’s C9-branded fitness collection flexes high-functioning fabrics: Freedom Fabric is a soft blend of polyester and spandex for lifestyle or fitness, while its Embrace Fabric hugs tight to the body for a cozy feel.

What was once a simple stretchy legging, it seems, has become an engineering marvel. Not too surprising, though, when you realize that about $48 billion is being spent on this activewear in the U.S. every year.

The story of a breakthrough product made by an upstart company that gets swallowed or crushed by America’s corporate behemoths is an old one. Lululemon is dead set on not letting that happen this time.

Tucked away in the basement of its Vancouver headquarters is a lab called Whitespace, the retailer’s research and development skunkworks. Here a team of about 50 employees works to come up with the brand’s next big idea. It’s developed lightweight seamless bras and made yoga pants with repurposed yarn combinations normally used in lingerie. The staff isn’t made up of just textile workers tasked with making new fabrics. It includes scientists as well as physiologists, mechanical engineers, neuroscientists and biomechanists.

Dr. Tom Waller, a sports technology Ph.D. whose work has been tested in everything from Olympic swimming to soccer’s World Cup, runs Whitespace. When it first opened six years ago, the R&D center was intended to explore what the company calls the “science of feel” and to better understand sensory experiences. “The mission at the time was to take some of our talent a little further into the future to explore human behavior and the macro trends shifting around us,” he said.

Yoga pants are tangible, but Waller aspires to the ethereal. He speaks of sweat as currency and using technology to unlock human potential. He talks about the “spectrum of sensory experience and desires” when describing the different kinds of fabrics Lululemon sells. “We unpack the physical, emotional and mental components of what it is to be human,” said Waller, “and then we drive the difference experiences of the sensory.”

“You have to be doing something pretty wrong to not have success in this type of product”

Alexandra Plante, director of innovation management at Whitespace, is responsible for taking what she calls “duct tape prototypes” and turning them into actual products. With a background in materials engineering, she delves into fabrics, yarns and polymers. Years ago, research was limited to focus groups and feedback from store associates who would query their shoppers. Now there are fabric labs, especially in the athletic-wear space. Lululemon’s research arm does motion-capture testing and uses pressure sensors that allow researchers to test how garments work as they move. The team can even test “hand feel” to help it figure out how to “engineer sensations” for that critical commercial moment when you feel the fabric for the first time, said Plante.

Back when Lululemon sold nothing but Luon, the company saw customers using the pants for all sorts of workouts, including high-intensity training the fabric was never meant for. So after R&D identified how consumers wore them, and for what, Lululemon developed material specific to each activity—hence the creation of pants for runners or dancers. Even Luon itself, the company’s original fabric, is different from what it was 20 years ago after years of tweaks and integration of new tech.

This watch-and-learn strategy became a virtuous circle, one that helped the craze turn into a full-on commercial earthquake.

Mistakes have been made, including one that was inherently—and spectacularly—calamitous. In 2013, Lululemon recalled pants for being too sheer, attributing the see-through problem to a manufacturing error. The subsequent destruction of the pants resulted in a loss of $67 million in sales. Choe said that problem has since been solved.

Now that it has a spectrum of products suited for most every movement, Lululemon has opened a pair of stores for those customers interested in still-experimental items. One of them, located in downtown Manhattan (the other is in Vancouver), looks more like a fashion boutique than a place to buy gear for the gym or yoga studio.

Yoga, as you might know, had been doing just fine for thousands of years without a stretchy uniform. The rise of yoga pants owes a lot to simple timing. Lululemon appeared on the scene at the tail end of the (perhaps unfortunate) leggings revolution, right about the time longer-term trends were leaning toward more casual dress.

The practice of yoga, a trifecta of physical, mental and spiritual disciplines involving specific postures and movements with origins in ancient India, was first popularized as an exercise system in the West in the 1980s. It dropped off for a while, only to return more commercialized than ever in the early 2000s. A 2016 study from Yoga Journal found that more than 36 million people in the U.S. practice yoga, up from about 16 million eight years ago. Boutique fitness followed, as women (and more than a few men) flocked to sparkling new studios to work out in groups for SoulCycle spin classes, sweat at Barry’s Bootcamp or sculpt their cores at Pure Barre. None of these expensive fads has anything to do with yoga in practice, but yoga clearly blazed a trail for them—and the clothing their adherents wear.

The biggest businesses now in the athletic wear space have invested heavily in growing their womenswear lines—especially in developing new fabrics and features for the once-simple yoga pant. In 2014, Nike Inc. began working toward a $7 billion sales target for its women’s business, reporting almost $5 billion in revenue. Executives realized women were “driving a larger global movement of health and fitness.” A year later, the company reported that the global growth for women’s business was outpacing that of men. That same year, Adidas AG began directing its youth brand, Neo, toward younger women. The German sports giant even brought on former Lululemon Chief Executive Officer Christine Day as a strategic adviser.

Adidas quickly became a formidable threat to Lululemon’s dominance. Early steps turned into exclusive designs for women through the PureBoost X line, leading to an even larger emphasis on active tops and bottoms, using technology called Climachill and Techfit, both focused on women’s training. Last year, women’s sales for Adidas grew by 28 percent, making it one of the company’s strongest segments.

Active bottoms and leggings are now a $1 billion industry, according to NPD Group analyst Marshal Cohen. Their appeal to consumers has yielded rapid sales growth that shows no sign of going away, he said. Where Lululemon found success with female consumers by providing a niche product that could satisfy casual and active uses, major brands such as Adidas and Nike completed the picture, confirming just how strong the athleisure trend could be.

These days, there are more than 11,000 kinds of yoga-specific pants available at retailers worldwide, according to data from retail research firm Edited, across both men’s and women’s apparel.

“Now that this easy-to-fit, easy-to-find, easy-to-wear, easy-to-care-for product has emerged as a fashionable product at the same time, you’ve got the perfect storm,” Cohen said. “You have to be doing something pretty wrong to not have success in this type of product.”