NEW YORK — U.S. stocks bounced back to record highs Tuesday as investors put an end to a two-day drop for technology companies. Energy and consumer-focused companies also made outsize gains.

In a reversal from the two previous days, investors put money into companies that stand to benefit from faster economic growth, including retailers, makers of basic materials such as paints and chemicals, energy companies and banks. Big-dividend companies, which are usually considered safer investments, did not do as well as the rest of the market.

Tech companies reversed their losses from Monday, although they remain well below their peak from last week.

“There’s no question that the rally in that sector can continue as long as investors’ sentiment remains positive,” said Brian Rehling, co-head of global fixed-income strategy at Wells Fargo Investment Institute. Rehling said he believes tech stocks are a bit too high, but not by a huge amount.

The Standard & Poor’s 500 index picked up 10.96 points, or 0.5 percent, to 2,440.35. The Dow Jones industrial average rose 92.80 points, or 0.4 percent, to 21,328.47.

The Nasdaq composite, which has a large concentration of technology companies, rose 44.90 points, or 0.7 percent, to 6,220.37, but did not get back to its record highs. The Russell 2000 index of smaller-company stocks added 6.77 points, or 0.5 percent, to 1,425.98.

Technology companies led the way once again. Facebook rose $2.24, or 1.5 percent, to $150.68 while Microsoft gained 87 cents, or 1.2 percent, to $70.65. Hard drive maker Western Digital added $3.41, or 3.9 percent, to $90.05.

Amazon helped retailers trade higher. The online giant picked up $15.88, or 1.6 percent, to $980.79 and Best Buy rose $1.07, or 1.9 percent, to $57.85. Home Depot climbed $1.25, or 1.2 percent, to $153.99.

Among materials companies, Dow Chemical jumped $1.25, or 2 percent, to $65.26 and Sherwin-Williams gained $5.31, or 1.5 percent, to $353.25.