Mattress makers are consolidating as digital upstarts threaten to upend their business.

Serta Simmons Bedding, the company behind Serta, Beautyrest and Tomorrow mattresses, announced on Tuesday that it's merging with online startup Tuft & Needle. Terms of the deal were not disclosed.

Serta, with around $3 billion in sales, is the world's largest bedding manufacturer.

The company is a top supplier to brick-and-mortar stores like Mattress Firm, owned by South African retailer Steinhoff International.

But Mattress Firm is under heavy pressure, weighed down by declining traffic at its stores.

Reuters reported earlier this month that it was considering a bankruptcy filing to close some of its 3,000 stores that were losing money. Mattress Firm did not respond to CNNMoney's request for comment.

Merging with Tuft & Needle signals that Serta, which is backed by a private equity firm, is scrambling to reposition its business away from selling to legacy retailers. It is trying to make a stronger push into the faster-growing online segment of the industry.

"This merger will greatly accelerate our growth and innovation in the direct-to-consumer segment, and significantly enhance our e-commerce capabilities," Serta CEO Michael Traub said in a release.

The company expects digital sellers to grab 20% of the $17 billion global bedding market in 2018.

Over the past few years, bed-in-a-box sellers like Casper, Tuft, Purple, Leesa and Yogabed have taken share away from Serta and reshaped the speed, cost, and convenience that many customers now expect from their bedding suppliers.

But the new players are shifting, too.

Casper, in an effort to differentiate itself in a crowded field and increase distribution, has been joining with Nordstrom, Target, and West Elm. Earlier this month, the company announced plans to open 200 stores of its own.

Tuft & Needle hopes merging will help it find scale and fight Casper's aggressive tactics with a jolt from Serta.

Clarification: This article has been updated to clarify the deal between Serta Simmons and Tuft & Needle