There may not be a bigger topic in the investing world these days than inflation. With prices growing at 8.3% year-over-year in the United States (as of the April data), our post-pandemic recovery has thrown the economy into a bit of a sticky situation. Sustained inflation is bad for many companies because it increases their input costs and forces them to raise prices for customers, hurting overall profitability and cash flow generation. This is typically bad for stock prices.

If you're worried about inflation impacting your portfolio, the consumer packaged goods (CPG) sector is a perfect hunting ground for potential investments. The Hershey Company (HSY -1.17%), one of the leading candy and snack food makers worldwide, is a great CPG stock to own in a high inflation environment. Here's why.

A person eating candy.

Image source: Getty Images.

More than just chocolate bars

We all know Hershey because of its famous chocolate bars and kisses. Founded before 1900 by Milton Hershey, the company has been a mainstay in American society for generations, which is where the company generates the majority of its sales today. However, through acquisitions over the years, Hershey's has grown far beyond just its flagship brand.

Today the company owns Jolly Rancher, Twizzlers, Brookside Chocolate, Pirate's Booty, and many other brands. None are more important than Reese's, whose peanut butter cups are the second-most-popular candy in the United States. These smart acquisitions have built up Hershey as the fifth-largest candy company in the world, with $9.3 billion in sales over the past 12 months. Since 1980, the stock's total return is over 47,000%, making it one of the best-performing securities of all time.

HSY Total Return Level Chart

HSY Total Return Level data by YCharts

Consistent pricing power and strong margins

So what has made Hershey's such a great investment, besides acquiring strong brands like Reese's? I think there are a lot of factors, but two main reasons are pricing power and strong profit margins.

Hershey's input costs are generally impacted by commodity prices, especially cocoa and sugar. When these prices rise, Hershey has to raise the prices it sells to retailers in order to maintain its profitability, all else being equal. Historically, candy companies have had incredible freedom to raise prices without impacting consumer demand. This is likely due to how small a candy purchase is relative to other everyday items like groceries and gasoline.

For example, even with all the inflation over the decades, a traditional Hershey Bar at Wal-Mart only costs around $1.00. If that has to rise to $1.10, $1.20, or even $2.00 a decade from now, I don't think people will make a huge fuss.

HSY Operating Margin (TTM) Chart

HSY Operating Margin (TTM) data by YCharts

This pricing elasticity leads to the second reason Hershey has been such a good stock, and that is its phenomenal profit margins. Over the last twelve months, Hershey's operating margins have reached an all-time high of 23.7%, up from around 18% ten years ago. Considering that inflation typically has a negative impact on profit margins, you can see why candy and CPG products, in general, have done well in high-inflation scenarios.

Growth in salty snacks

On top of its core candy products, The Hershey Company has started to move into the salty snack category through acquisitions. In 2018, it acquired Pirate's Booty, and more recently has added SkinnyPop popcorn and Dot's pretzels to its arsenal. These are not nearly as big as its candy business, but the brands are growing much quicker.

For example, in Q1 of 2022, SkinnyPop retail sales grew 13.4%, Pirate's Booty 55.4%, and Dot's Pretzel's 103% year-over-year. These are phenomenal numbers for the CPG sector, and should help drive Hershey's overall top-line growth this decade.

You shouldn't expect hyper-growth from a mature large-cap stock like Hershey. But with durable brands, consistent pricing power, and a big opportunity in salty snacks, the stock should put up consistent returns over the long haul, no matter how bad inflation gets.