The S&P 500 rose 9.25 points, or 0.7 percent, to 1,319.44. The Dow Jones industrial average gained 81.13 points, or 0.7 percent, to 12,279.01. The Nasdaq composite rose 26.21, or 1 percent, to 2,756.89.
Rising gas prices helped drag down consumer confidence in March. The Conference Board said its confidence index dropped to 63.4 from 72 in February.
The fall comes after five straight months of gains, but some economists had expected the decline to be even worse. Goldman Sachs had forecast a drop to 60, believing that high gas prices would pinch spending. The University of Michigan confidence survey also took a steep fall last week.
The Conference Board survey also had a surprising result: the index measuring consumers' assessment of current conditions gained from February, putting it at the highest level since November 2008.
``Now, you can't say things are going worse than they were a month ago,'' said Thomas Simons, money market economist at Jefferies & Co.
Home Depot Inc. rose 2.9 percent, the most of the 30 companies in the Dow Jones industrial average. The retailer said it would buy $1 billion of its own stock with cash from selling bonds.
Stocks started lower after a report showed that home prices fell in 19 of the 20 large U.S. cities tracked by the S&P/Case-Shiller index. Washington was the only city in which prices rose. Prices have fallen 3 percent overall in the past year.
Lennar Corp. fell 3.4 percent on news that housing prices dropped in most major cities even after the homebuilder reported a surprise profit for the latest quarter. Other homebuilders fell, too. KB Home dropped 1.9 percent. Toll Brothers slipped 0.2 percent.
General Electric Co. rose 0.6 percent after announcing plans to buy 90 percent of Converteam, a France-based electrical equipment maker.
Two stocks fell for every one that rose on the New York Stock Exchange. Consolidated volume came to 3.6 billion shares.