U.S. stocks closed higher on Monday as technology stocks recovered from a wobbly performance last week.

The Dow Jones industrial average rose about 140 points and hit intraday and closing records, surpassing a previous all-time high of 21,391.97, which was set last week.

The S&P 500 gained 0.8 percent to also reached record levels, with information technology rising 1.4 percent to lead advancers. The Nasdaq composite outperformed, rising 1.65 percent.

"Tech stocks, after being on everyone's sell list over the past few days, are now back on people's buy lists," said Anthony Conroy, president at Abel Noser. "Looks like there's some buying on the dip."

Large-cap technology stocks like Facebook, Amazon, Apple, Netflix and Google-parent Alphabet all closed higher. Amazon also hit an all-time high at the open.

Last week, valuation concerns sent the overall sector lower by around 0.8 percent. Tech is by far the best-performing sector of the year, rising 17.2 percent in the period.

"I don't know where the optimism is coming from. That's not to say we should be negative. I just don't see any reason for excessive optimism or pessimism right now," said Randy Frederick, vice president of trading and derivatives at Charles Schwab.