(CNBC) — U.S. stocks closed slightly higher on Wednesday, notching record highs, as a gain in the energy sector offset losses in tech.

The Dow Jones industrial average rose 37 points, with Chevron contributing the most to the gains. Apple, however, was the biggest loser in the index.

The S&P 500 eked out intraday and closing records as energy gained more than 1 percent to lead advancers. Technology stocks were among the worst performers, however, falling 0.2 percent after closing at a record high on Tuesday.

Note: Read our discussion guidelines before commenting.