Home Depot (NYSE:HD) had the wind at its back in 2017. Home prices increased steadily, economic growth was strong, and its aggressive e-commerce strategy kept online rivals from chipping away at its business.

The favorable economic trends supported robust housing demand that, in turn, lifted improvement spending to a post-financial-crisis high. That surge disproportionately benefited the market leader, and Home Depot's 40% stock-price gain during the year made it one of the best-performing members of the Dow.

Below, we'll look at the key ways that the retailer beat Wall Street's expectations in the past year while extending its lead over chief rival Lowe's (NYSE:LOW).

Winning share

Home Depot began the year targeting modest, but still strong, revenue gains. After achieving a 5.6% comparable-store sales boost in 2016 (versus Lowe's 4.2%), CEO Craig Menear and his team forecast a slight deceleration -- down to 4.6% in 2017.

A customer inspects a piece of lumber.

Image source: Getty Images.

The year started out just as executives had predicted, with first-quarter sales slowing as customer traffic growth dipped to 1.6% from 2.9% in the prior quarter. Operating trends rapidly improved from there, though.

Customer traffic growth bounced back up to nearly 3% in the second quarter. That success, plus a spike in average spending, powered a record quarter for the retailer, as comps rose by 6.3%. In contrast, Lowe's missed management's growth target for the period, and the company announced a strategic shift aimed at winning back market share through boosting store hours.

That initiative didn't deliver the hoped-for results. Instead, Lowe's comps were just 5.7% in the fiscal third quarter, while Home Depot expanded sales at a blistering 7.9% rate. In response, the market leader lifted its full-year outlook for the second time, and now predicts comps will rise by 6.5% in 2017. Lowe's still believes its comps will improve by 3.5%, consistent with management's initial outlook issued in early March.

Reaching goals

All of that winning put Home Depot ahead of many of the long-term goals that management issued back in 2015. Thanks, in part, to a hurricane-fueled sales bump, the retailer is set to pass $100 billion of annual revenue in fiscal 2017 rather than in 2018.  Operating margin is already above 14.5%, the profitability level that executives had hoped to reach sometime in 2018. Return on invested capital is over 30%, too, making Home Depot one of the most efficient companies on the market.

LOW Operating Margin (TTM) Chart

LOW Operating Margin (TTM) data by YCharts.

How about 2018?

Home Depot's upcoming results will depend on continued strength in the housing market and a healthy performance for the economy overall. As for the next few months, hurricane rebuilding efforts should lift sales into the first quarter of the new year, and that's a key reason why executives raised their 2017 comps outlook in November.

Yet management sees a long runway for growth beyond that. They point to favorable metrics, including relatively tame home prices (when adjusted for inflation) and the elevated age of housing stock as support for the idea that the industry could see several more years of expansion ahead. Home-improvement spending has more than doubled since hitting a post-recession low in 2010, but it's still $140 billion below the $900 billion annual peak set in 2006.

Put it all together and, while Home Depot will probably slow its expansion rate in 2018, investors have every reason to expect additional market-share gains and healthy earnings. Those returns will be supplemented, meanwhile, by robust cash returns from Home Depot's stock-repurchase plan and an unusually generous dividend payment.

Demitrios Kalogeropoulos owns shares of Home Depot. The Motley Fool has the following options: short May 2018 $175 calls on Home Depot and long January 2020 $110 calls on Home Depot. The Motley Fool recommends Home Depot and Lowe's. The Motley Fool has a disclosure policy.