"We're getting a positive reaction to her testimony," said Jeff Kravetz, regional investment strategist at the Private Client Reserve at U.S. Bank. "What happened was she was more dovish than the market expected in her prepared remarks."

Fed Chair Janet Yellen said the central bank is likely to start reducing its massive $4.5 trillion portfolio later this year. The Fed bolstered the portfolio, known as the balance sheet, as a way to stimulate the economy during and after the financial crisis .

The S&P 500 gained 0.73 percent and closed at 2,443.25, with real estate and information technology leading advancers. The Nasdaq composite outperformed, rising 1.1 percent to close at 6,261.17 as shares of PayPal hit a record high .

U.S. equities rose on Wednesday as investors parsed through testimony from the top-ranking Federal Reserve official.

She also said the balance sheet reduction and rate increases would be gradual. Yellen also noted rates won't have to rise as much to get to neutral, as in previous decades.

"After months of talking tough on rates it appears that Janet Yellen has changed her tune. My belief is that the original hawkishness was contingent on a belief that pro growth policy changes were right around the corner," Jim Iurio, managing director of TJM Institutional Services, said in an email.

"However, this takes away one of stock markets primary worries, that the Fed would raise rates before the political landscape could be sorted out. In other words, this is a long way of saying the Fed's got your back," he said.

Yellen delivered her remarks in front of Congress on Wednesday. She also answered questions about monetary policy and the health of the U.S. economy.

Treasury yields fell after Yellen's testimony was released. The benchmark 10-year note yield traded at 2.32 percent, down from 2.35 percent earlier. The two-year yield, which is more sensitive to monetary-policy changes, fell from 1.38 percent to 1.34 percent.

"There seems to be a resurgence of the tug-of-war within the Fed regarding the rates trajectory," said Quincy Krosby, chief market strategist at Prudential Financial. "At here [June] press conference, she indicated that the bar to keep rates lower for longer was higher. Now it seems like that may change."

The Fed raised rates last month for the second time this year. The central bank also released details about how it plans to unwind the balance sheet.

"I think she knows she's not going to be in her job as of February of next year, so she want's to normalize rates" as much as possible, said Aaron Anderson, head of research at Fisher Investments.

The Fed also released its latest edition of the Beige Book, which summarizes the central bank's thoughts on current economic conditions. In it, it said it sees the U.S. economy growing at a "slight to moderate" pace.

Elsewhere, gold futures for August delivery gained $4.40 to settle at $1,219.60 per ounce.

About four stocks advanced for every decliner on the New York Stock Exchange, with an exchange volume of 458.30 million and a composite volume of 2.205 billion in afternoon trade.