A broad base of stocks has driven the market’s recent gains, an encouraging sign for investors wondering how long the year’s formidable rally can continue.

The S&P 500 has risen 25% in 2021 and last week notched its 66th record close of the year—more new highs than in any year since 1995. Recent gains have come from a diverse array of stocks. Last week saw record closes from dozens of names, ranging from Estee Lauder Cos. and AutoZone Inc., to Netflix Inc. and Home Depot Inc.

The...

A broad base of stocks has driven the market’s recent gains, an encouraging sign for investors wondering how long the year’s formidable rally can continue.

The S&P 500 has risen 25% in 2021 and last week notched its 66th record close of the year—more new highs than in any year since 1995. Recent gains have come from a diverse array of stocks. Last week saw record closes from dozens of names, ranging from Estee Lauder Cos. and AutoZone Inc., to Netflix Inc. and Home Depot Inc.

The advance isn’t limited to shares of the biggest U.S. stocks. The Russell 2000 benchmark of small-cap stocks is up 2% in November, in line with the S&P 500’s advance, as investors bet on companies they hope can react quickly to rising inflation.

And a popular technical indicator for market breadth has trended higher. The share of S&P 500 stocks closing above their 50-day moving averages rose early last week to 75%, its highest level since May.

Investors see a broad push higher as a promising sign for the durability of the rally. Relying on the performance of multiple sectors means indexes are less likely to falter if a few big names stall. That has been a concern during times when the megacap tech stocks that hold sway over the S&P 500 pushed the index higher while a diverse set of smaller companies tried to keep up.

Home Depot shares hit a new closing high Friday at $408.69.

Photo: Yi-Chin Lee/Associated Press

“If you look at the markets today, that widespread strength is evident,” said Matt Stucky, senior portfolio manager at Northwestern Mutual Wealth Management Co. “There’s certainly momentum behind this market because of how many different industries and sectors are participating in the upward move.”

Near the end of the week, however, there were signs of weakness under the surface of major indexes.

The percentage of S&P 500 members above their 50-day moving averages ticked lower. And even as the Nasdaq Composite closed at a record Thursday, 409 Nasdaq stocks made new 52-week lows, the highest daily number since March 2020, according to Willie Delwiche, investment strategist at All Star Charts.

“I don’t know if it will be the case this time, but when the market is heading for trouble, new low lists crescendo in size,” he wrote. “This is not unlike tremors before an earthquake.”

Investors this week will look for clues about the prospects for different sectors in earnings reports from tech giant HP Inc., consumer-electronics retailer Best Buy Co. , food maker J.M. Smucker Co. and medical-device company Medtronic

PLC.

Stronger-than-expected profits have buoyed stocks recently. Analysts expect that profits from companies in the S&P 500 grew 40% in the third quarter from a year earlier, according to FactSet. That is higher than the 27% growth projected when the quarter ended in September. Forecasts for next year’s earnings growth have also ticked higher.

Investors headed into earnings season worried about how rising inflation and supply-chain problems would affect corporate results, said Jessica Bemer, portfolio manager at Easterly Investment Partners.

“Third-quarter earnings were generally quite positive,” she said. “There’s certainly a level of relief there across the board.”

But the market’s recent climb has outpaced the brightening outlook for earnings, leading valuations to turn higher after trending down for much of 2021. The S&P 500 traded Thursday at 21.6 times its projected earnings for the next 12 months, above a five-year average of 18.7 and up from a recent low of 20.2 in early October, according to FactSet.

Valuations shot higher during the market’s recovery from its early 2020 pandemic-induced downturn, as the Federal Reserve cut interest rates to near zero and lawmakers in Washington approved trillions of dollars in economic stimulus. Some analysts say it makes sense that investors are willing to pay more for stocks when government bonds offer little yield.

Goldman Sachs analysts wrote in a research note last week that they expect profit growth to lift the S&P 500 next year while the stock index’s price-to-earnings multiple stays about where it is.

Many investors say they expect valuations will eventually revert to more historically normal levels, though they say they can’t predict when the market’s current richness might subside. Many are keeping an eye on markers of inflation as the Fed considers when to begin raising interest rates, a move that would affect calculations of how much companies’ future earnings are worth.

“The markets are sort of like an elastic band: They can become stretched but they can continue to stretch further,” said Jim Baird, chief investment officer at Plante Moran Financial Advisors. “At some point we would expect to see those valuations come back in.”

Write to Karen Langley at karen.langley@wsj.com