The day's biggest gainers included Amazon.com Inc , up 2.9% at $327.07; Yahoo Inc , up 2.3% at $33.83; and LinkedIn Corp , up 5.9% at $169.10.
The Global X social media index rose 2.4% to close at 18.50.
But gains in the blue-chip Dow Jones industrial average were capped by a decline in bank stocks. Goldman Sachs Group fell 1.3% to end at $156.56. JPMorgan Chase & Co slipped 0.3% to close at $58.85.
Alcoa Inc kicked off the earnings season after the bell on Tuesday, reporting a first-quarter loss due to a restructuring charge. But the stock jumped more than 2% in extended-hours trade.
Retailer Bed, Bath & Beyond is scheduled to report earnings on Wednesday, while banks JPMorgan Chase and Wells Fargo & Co will release results on Friday.
"Ironically, while the S&P is just shy of its all-time high, the number of S&P constituents that have lowered their quarterly EPS outlook is also at an all-time high," said Robbert van Batenburg, director of market strategy at Newedge USA, LLC, in New York.
More From This Section
"While this is a concerning statistic, it has become a tradition for many companies to gradually manage EPS estimates lower throughout the quarter and then subsequently 'beat' the - excessively low - consensus estimates."
S&P 500 companies' first-quarter earnings are projected to have increased just 1% from a year ago, Thomson Reuters data showed. The forecast is down sharply from the start of the year, when profit growth was estimated at 6.5%.
Companies across America are blaming the brutal winter for weak first-quarter results, but investors are expecting a quick rebound in the second quarter.
Financial stocks were in the spotlight as regulators finalized the rule to limit banks' reliance on debt. Under the rule, the eight biggest US banks must raise a total of about $68 billion in capital by 2018 to comply with a new rule designed to prevent another financial crisis.
The rules would apply to JPMorgan Chase, Citigroup , Bank of America , Wells Fargo, Goldman Sachs, Morgan Stanley , Bank of New York Mellon and State Street.
Biotechnology stocks, which had been punished in the recent selloff, seesawed between gains and losses on Tuesday. The Nasdaq biotechnology index fell 0.4%. Gilead Sciences Inc was among the S&P 500's biggest decliners, down 3.1% at $70.01.
The Dow Jones industrial average rose 10.27 points or 0.06%, to end at 16,256.14. The S&P 500 gained 6.92 points or 0.38%, to finish at 1,851.96. The Nasdaq Composite added 33.234 points or 0.81%, to close at 4,112.986.
Tuesday's advance followed the S&P 500's biggest three-day retreat since late January and the Nasdaq's steepest three-day drop since November 2011.
The benchmark S&P 500 index rose above its 50-day moving average around 1,840, a key support level. The index has managed to stay above 1,840 several times over the past month.
In contrast to the day's positive trend, shares of Gigamon Inc plunged 33.9% to close at $17.31. The maker of network traffic management software estimated lower-than-expected first-quarter revenue.
About 6.7 billion shares changed hands on US exchanges, slightly below the 6.8 billion average so far this month, according to data from BATS Global Markets.
Advancers outnumbered decliners on the New York Stock Exchange by a ratio of about 2 to 1. On the Nasdaq, 17 stocks rose for nearly every nine that fell.