Walmart (NYSE:WMT) is already a dominant force in groceries. It took about 26% of all grocery sales in the U.S. last year, more than doubling those of second-place Kroger (NYSE:KR).

Over the last year and a half, though, Walmart has received an extra push from Amazon (NASDAQ:AMZN), which aggressively pursued the grocery market with the acquisition of Whole Foods last summer. Walmart responded by investing in its online grocery ordering capabilities, rapidly expanding its online order and pickup service, and experimenting with various home-delivery options as well. As a result, Walmart managed to take 11% of the online grocery market last year, according to estimates from Deutsche Bank analyst Paul Trussell, trailing only Amazon.

A Walmart associate loading a car full of groceries.

Image source: Walmart.

Trussell expects Walmart's online grocery operations to fuel market share expansion both online and in stores. He sees Walmart's share of online grocery sales climbing to 17% by 2025 (although still trailing Amazon). The expansion of its online grocery operations should enable Walmart to dominate mindshare when people think of groceries, enabling it to grow its portion of brick-and-mortar sales as well.

The rich get richer

The push into online grocery sales isn't cheap. Online orders require employees in the store to select items, package them, and deliver them (either to a curbside car or to a customer's home). Pickup orders require space in stores to keep items while awaiting customers.

Walmart already has a lot of those operations in place as part of its general merchandise sales. Expanding to groceries is significantly easier for Walmart than it is for Kroger. That may be why Walmart is willing to offer free pick up on orders over $35 while Kroger charges a convenience fee.

What's more, Walmart is willing to take a lower gross margin on sales if it can make up for it in volume. Indeed, Walmart's investments in online grocery ordering and pricing led to its best quarter of grocery sales growth in nine years in the second quarter. Meanwhile, Kroger's identical store sales grew just 1.6% in the second quarter compared to Walmart's "mid-single-digit" growth in comparable grocery sales.

Walmart is simply in a better position to invest in expanding its market share of the grocery industry as more sales shift online. Of course, it can afford to invest with billions in cash sitting on its balance sheet and free cash flow of over $11 billion through the first six months of fiscal 2019. Kroger, by comparison, has just a few hundred million in cash.

Market share winners and losers

The vast majority of growth in the grocery industry is coming from online sales. While fresh food sales increased 3.5% year over year for the 52-week period ending June 30, according to Nielsen, 82% of that growth came from online sales. In other words, if you're not investing heavily in online sales, you're probably losing market share.

Even existing grocery giants like Kroger are losing out despite their investments. In fact, Kroger grew online sales 50% year over year in the second quarter. But because it's operating off such a small base of sales, that growth barely pushed its total sales growth to half of the industry growth rate last quarter (1.8%).

Meanwhile, Walmart and Amazon are both spending big to win the online market and thus a big share of the overall grocery market.

Amazon is taking steps to move more of Whole Foods' sales online. It's rolling out free delivery and curbside pickup for Prime members in select cities, with plans to eventually offer the services nationwide. It also added Whole Foods' Everyday 365 brand to its online marketplace, and Trussell expects those efforts to keep Amazon in the lead in online groceries.

Those legacy brick-and-mortar grocers that can afford to invest online in an effort to keep pace with Amazon will win market share from those that don't have the resources to do so. We're already seeing it start, and the shift could become even more dramatic over the next decade as Walmart and Amazon continue to dominate the digital supermarket.

Considering Walmart's current dominance of the much bigger brick-and-mortar grocery industry, its share of the overall grocery market is only getting bigger.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.