Auto parts are getting pricier, but they are in a sweet spot for the retailers that sell them. They still aren’t close to generating the kind of sticker shock that fully assembled cars can set off these days.

Advance Auto Parts said in its earnings call on Tuesday that comparable-store sales increased 8.2% in its fourth quarter compared with a year earlier, trouncing the 5.7% figure analysts polled by FactSet had expected. For the full year, the retailer saw comparable sales grow 10.7%, topping its own guidance and quite the...

Auto parts are getting pricier, but they are in a sweet spot for the retailers that sell them. They still aren’t close to generating the kind of sticker shock that fully assembled cars can set off these days.

Advance Auto Parts said in its earnings call on Tuesday that comparable-store sales increased 8.2% in its fourth quarter compared with a year earlier, trouncing the 5.7% figure analysts polled by FactSet had expected. For the full year, the retailer saw comparable sales grow 10.7%, topping its own guidance and quite the step-up compared with the 2.4% growth it saw in 2020. Its larger peer O’Reilly Automotive saw comparable sales grow 13.3% in 2021 after seeing 10.9% growth in 2020.

Inflation has hit auto parts, but their prices haven’t grown at the pace of used cars. Motor-vehicle parts and equipment were 12.6% more expensive in January compared with a year earlier, while used-car prices increased 40.5%, according to data from the U.S. Bureau of Labor Statistics. An expensive market for cars likely means consumers are willing to tolerate higher spending to keep their vehicles on the road. With supply-chain issues still crimping new-car supply, Evercore expects to see elevated pricing for used cars continue into at least 2023.

For now, that dynamic should keep helping auto-parts sellers fatten their bottom lines. Advance Auto Parts had an operating margin of 7.6% in 2021, which was its fourth consecutive year of margin growth. Both O’Reilly and AutoZone hit their best annual operating margins in their respective fiscal years for 2021.

The sector probably still has some room left to run, though probably not at 2021’s breakneck pace. For one, U.S. vehicle miles traveled still aren’t back to pre-pandemic levels. Figures for 12-month vehicle miles traveled remained 2.1% below those seen two years earlier as of November, according to data from the U.S. Federal Highway Administration. As more cars get back on the road for commutes, there should be more wear and tear on a car population that has only gotten older. Data from Experian also shows that the number of vehicles aged 6-12 years, too old for their original warranties and requiring more replacement parts, has grown to account for almost a third of all vehicles in operation as of third quarter 2021, about three percentage points higher than 2019.

Worth watching is how competitive dynamics will shake out as retailers chase market share. O’Reilly, for example, last week said it will make “price investments” to its professional-service customers, which means it will strategically lower prices to gain market share. Advance Auto Parts, which relies more on professional-service customers, said on Tuesday morning that it won’t make changes to its pricing strategy and instead is focusing on selling more of its private-label brands, which generally yield higher margins. Rather than taking market share away from each other, it is more likely that those actions will take a bite out of small, independent auto-parts retailers that saw bigger impacts from supply-chain issues. For professional customers in particular, parts availability and delivery speed are more important than price.

Investors were slow to notice their potential in 2020, but auto-parts retail stocks finally got rolling last year. An equal-weighted basket of four auto-parts retailers are now up 49% compared with a year earlier. On a valuation basis, O’Reilly and Advance Auto Parts are hardly in the bargain bin; as a multiple of forward revenue, both companies’ shares are trading above their respective five-year averages. Still, none of the auto-parts retailers have beat the share-price performance of the broader retail sector compared with pre-pandemic levels. And, unlike home-improvement, furniture or groceries, any incremental return back to the office should drive more business to auto-parts retailers.

Optimism is already baked into auto-parts retailers’ share prices, but compared to the broader retail sector, there might still be plenty of road ahead of them.

Write to Jinjoo Lee at jinjoo.lee@wsj.com