By Anna Hirtenstein and Karen Langley

U.S. stocks rose Tuesday as technology shares recouped some of their recent losses.

The S&P 500 added 0.5%, and the tech-heavy Nasdaq Composite climbed 1.1%. The Dow Jones Industrial Average hovered around the flatline.

The S&P and Nasdaq built on gains from Monday after sustaining big losses earlier in the month. Investors endured volatile trading sessions as the big tech stocks pulling the market steadily higher suddenly pulled back. Those stocks appear to have stabilized in recent sessions.

Tech shares climbed Tuesday, extending the previous day's rally. Salesforce.com rose 1.7%, and Microsoft added 1%. Nvidia shares edged up 0.3% after the graphic-chip maker said earlier this week it would acquire chip designer Arm Holdings from SoftBank.

Looking ahead, investors face uncertainties about the spread of the coronavirus, efforts to produce a vaccine, the pace of economic recovery and the outcome of the coming U.S. elections. But many analysts believe stocks have room to rise.

"Right now, it looks to us like the economy's going to be improving. They're keeping interest rates low. And so it's still a favorable environment for stocks, especially growth companies," said Tom Plumb, president and portfolio manager at Plumb Funds.

A wave of multibillion-dollar deals emerging earlier this week from well-known tech companies have helped boost stock benchmarks, underscoring the outsize role of giant firms in U.S. equity markets.

"There's been exuberance in the tech sector and valuations are high, but M&A means some people think there's still some assets that aren't overvalued, they may actually be undervalued," said Ludovic Subran, chief economist at Allianz. "M&A can be perceived as a sign of undervaluation" and some people will be buying.

Among other individual stocks, shares of NextEra Energy rose 4.3% after the utility raised its outlook for next year and announced a stock split. Tesla shares surged 9.1%, continuing to recover losses from earlier in the month.

Data Tuesday showed U.S. industrial production rose in August but at a lower rate than earlier in the summer, indicating the recovery in manufacturing is slowing.

Earlier Tuesday, key economic statistics showed that China's economic recovery accelerated in August. Retail sales in the Asian nation returned to pre-coronavirus levels with their first month of growth this year. Other major indicators, including factory production, investment and property activity, all gathered pace, signaling a strong rebound for the world's second-largest economy.

"It paints a fairly robust picture of the Chinese economy," said Sebastien Galy, a macro strategist at Nordea Asset Management. "It's a solid positive surprise, but the data tells you more about the message the Chinese government wants to give you."

The Shanghai Composite Index closed up 0.5%, and Hong Kong's Hang Seng Index rose 0.4%.

In Europe, the pan-continental Stoxx Europe 600 rose 0.7% from an anticipated boost in Chinese demand for European goods.

The yield on 10-year U.S. Treasury bonds ticked up to 0.679%, from 0.669% on Monday.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com and Karen Langley at karen.langley@wsj.com