(CNBC) — Stocks struggled to hold on to gains Tuesday as investors grappled with rising U.S. interest rates.

The S&P 500 rose 0.1 percent as gains in Twitter, Advanced Micro Devices and Walmart offset a decline in PPG Industries that led the materials sector lower. The Dow Jones Industrial Average rose 12 points with Apple and McDonald’s contributing to the rise. The Nasdaq Composite rose 0.2 percent as gains in major tech shares kept losses in check.

Shares of Facebook and Amazon rose 0.8 percent and 0.2 percent, respectively. Netflix gained 2.5 percent. Apple’s stock also climbed 1.2 percent.

Note: Read our discussion guidelines before commenting.