By Anna Hirtenstein, Frances Yoon and Karen Langley

U.S. stocks rose Wednesday on optimism about the prospects for a global economic recovery in the wake of the coronavirus pandemic.

The S&P 500 gained 1.7%, erasing Tuesday's losses, as of the 4 p.m. close of trading in New York. The Dow Jones Industrial Average added about 369 points, or 1.5%, and the technology-heavy Nasdaq Composite rose 2.1%.

The gains were broad, with all 11 sectors of the S&P 500 in the green. The beaten-down energy group led the S&P 500 sectors, rising about 4% as crude oil prices rallied.

Airline shares, which have been battered by the halt in global travel, popped, with United Airlines, Delta Air Lines and Southwest Airlines up 4.4% or more. Airline executives have said people are starting to book flights again, a potential inflection point for the industry.

State governments hoping to revive their economies are taking steps to ease the restrictions put in place to limit the spread of coronavirus. In one sign of a positive investor outlook, the Russell 2000 index of small-capitalization companies, which tend to be sensitive to the domestic economy, gained 2.7%, outpacing the major large-cap indexes.

"If the economic reopenings are going well, or better than expected, on a consistent basis, the small caps will let us know," said Chris Hyzy, chief investment officer at Merrill and Bank of America Private Bank.

Investors are continuing to focus on any sign of hope for a vaccine. Shares of Inovio Pharmaceuticals jumped 11% after its experimental coronavirus vaccine induced immune responses in mice and guinea pigs, according to a new study published in Nature Communications. Researchers from the biotechnology company and its academic collaborators said the data were encouraging but more testing is needed in animals and humans.

The Inovio news came two days after drugmaker Moderna said the first human study of its experimental coronavirus vaccine showed promise in some of the healthy volunteers who were vaccinated. That report helped send stocks surging Monday.

Many investors expect to continue seeing big market reactions as news trickles in about the success of business openings and the race to develop treatments and vaccines.

"What's key is how we open up this economy going into the fall and whether or not the opening of the U.S. economy induces a coronavirus surge," said Quincy Krosby, chief market strategist at Prudential Financial. "We remain at the mercy of the virus."

Investors carefully watching the Federal Reserve for signs of future monetary policy got their first opportunity Wednesday afternoon to parse the minutes of the central bank's April 28-29 meeting. Officials spent much of that meeting reviewing progress on lending programs to backstop everything from short-term funding markets to markets for corporate debt and municipal bonds.

Meanwhile, the latest earnings reports from retailers continued to be a mixed bag. Home-improvement retailer Lowe's beat analysts' estimates with a higher quarterly profit as online sales grew during the pandemic. But the company withdrew its financial guidance for the year, citing an uncertain business outlook from the pandemic. Shares edged down 0.2%.

Target posted stronger-than-expected sales growth but said its per-share earnings fell by nearly two thirds from the same period last year. Shares fell 2.6%.

"There's a consensus around the fact that companies can adapt [to the pandemic], but at the expense of slightly higher costs," said Michael Hewson, chief market analyst at brokerage CMC Markets.

Stocks have rebounded sharply from their March lows, with the S&P 500 up more than 30%. But the rebound has been more pronounced in the U.S., where tech giants have pulled indexes higher, said Sebastian Mackay, a multiasset fund manager at Invesco.

"It's been a fairly narrowly driven rebound in the [U.S.] market. If you look at the European market or some of Asia, the rebound looks much less impressive," he said.

The yield on the 10-year U.S. Treasury ticked down to 0.675% from 0.711% Tuesday. Bond yields fall as prices rise.

Overseas, the Stoxx Europe 600 index rose 1%. Japan's Nikkei 225 rose 0.8%, while the Shanghai Composite declined 0.5%.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com, Frances Yoon at frances.yoon@wsj.com and Karen Langley at karen.langley@wsj.com