U.S. stocks rose on Tuesday after a two-day decline, helped by gains in technology shares.

But the market was well off its highs for the session, with shares of homebuilders falling broadly after KB Home forecast a drop in gross margins for the first quarter. Homebuilder stocks had been up earlier in the session, but KB Home was last down 13.7 percent, while a housing index was down 0.9 percent.

The S&P technology sector was among the day's best performers, with a 1.3 percent gain. Apple shares were up 2 percent and among the most actively traded on Nasdaq after Credit Suisse upgraded the stock to outperform, citing increased projections for iPhone sales in fiscal 2015 and 2016.