The U.S. economy grew rapidly in the second quarter and exceeded its pre-pandemic size, but the outlook has suddenly turned cloudier due to the fast-spreading Delta coronavirus variant.

Virus cases are rising again, particularly in parts of the country where vaccination rates remain low. The Centers for Disease Control and Prevention this week recommended that vaccinated people resume masking indoors in places with high or substantial transmission of coronavirus, leading some local governments and businesses to reinstate restrictions on activity.

Apple Inc., for instance, said it would require workers and customers to wear masks in more than half of its retail stores, and Google delayed its return-to-the-office plans until mid-October. Several private and public employers have said they would require workers to be vaccinated or regularly tested for infection.

All of this has raised uncertainty about whether consumers and workers will retreat again, as they did last year. For now, forecasters generally don’t expect the spread of Delta to make a major dent in the U.S. economy, in part because businesses and consumers have learned to adapt to each wave of the pandemic.

Still, the Delta variant’s fast spread, initially in many emerging nations abroad, shows the U.S. economy remains vulnerable as long as the pandemic persists.

Shortages of available workers could restrain economic growth starting later this year. A San Rafael, Calif., boxing gym sought workers in early July.

Shortages of available workers could restrain economic growth starting later this year. A San Rafael, Calif., boxing gym sought workers in early July.

Photo: Justin Sullivan/Getty Images

“What you worry about is how many disruptions are we going to continually have to deal with?” said Diane Swonk, chief economist at Grant Thornton. “In the U.S. economy, there is some downside risk that some people don’t go out and don’t go out to eat as much as they did, they don’t travel as much.”

Gross domestic product, the broadest measure of U.S. goods and services produced, grew at a 6.5% annual rate in the second quarter, up slightly from a 6.3% growth rate in the first three months of the year, the Commerce Department said Thursday. The reading was below economists’ estimates but pushed the size of the economy above its pre-pandemic level, a milestone that underscores the speed of the recovery that began in May 2020.

The strong spring growth was fueled by trillions of dollars in fiscal stimulus and consumer spending that jumped at an 11.8% annual rate as more people received vaccinations and businesses reopened. U.S. payrolls continued to grow during the quarter, expanding the labor market by an average of nearly 600,000 a month. More recently, initial jobless claims last week resumed their decline.

Economists see two main ways the spread of the Delta variant could derail the robust recovery. First, some state and local governments could reimpose restrictions on businesses. Second, consumers could curtail spending on travel, dining out and moviegoing out of heightened cautiousness.

So far, new restrictions have been limited in scope, but the list is growing. They include the reinstatement of indoor-mask rules in some localities such as Los Angeles County. Walt Disney Co. said it will require visitors to Walt Disney World in Orlando, Fla., and Disneyland Resort in Anaheim, Calif., to wear masks indoors, effective Friday. Three music clubs in New Orleans—including Tipitinas—said they would require people attending shows to provide proof of vaccination or a negative Covid-19 test for entry, also effective Friday.

Americans don’t appear to be retreating into their homes as the Delta variant spreads. Flight volumes and hotel-occupancy rates continue to rise, according to an analysis by Jefferies. Public-transit usage is also gaining ground, though it is down compared with pre-pandemic levels, Jefferies said.

The increasing level of vaccinations in the U.S. has made people more likely to keep working and spending money despite the rise in cases.

“I really don’t expect anything like we saw in the spring of last year,” said Ben Herzon, executive director at forecasting firm IHS Markit. “Going forward we’ll just see how high the case count gets and how nervous some people get.”

Rising inflation, continued supply-chain disruptions and a shortage of available workers also are factors that could restrain the economy.

Budweiser brewer Anheuser-Busch InBev SA said it was grappling with how to mitigate a range of higher costs to protect profitability, though its sales reached pre-pandemic levels in the second quarter. It said barley and freight had gotten more expensive, and that greater demand for cans in the U.S. had forced it to import them from elsewhere, further adding to its costs.

Shipping bottlenecks and commodities costs are helping drive inflation in the U.S. WSJ visits a patio-furniture factory in China to see why refurbishing your backyard could be pricier this year. Photo: Patrick Fok The Wall Street Journal Interactive Edition

Similarly, Nescafe coffee maker Nestlé SA warned that costs for transportation, commodities and packaging were all rising, with little indication as to when the current bout of inflation would end.

Elsewhere, logjams at seaports around the world have left toy companies such as Hasbro Inc. and Mattel Inc. scrambling already to ensure they will have sufficient supplies for the holiday shopping season. Toy-industry veterans say this year’s disruption is worse than when Covid-19 first struck last year, temporarily shutting many ports, factories and stores. Ocean freight bottlenecks have led to long delays for shipping from China and rates that are far higher than usual. Toy makers are also grappling with rising costs for materials and labor, leading some to raise prices.

Still, many analysts expect these supply constraints and bottlenecks to ease. Demand—particularly for long-lasting goods that consumers snatched up earlier in the pandemic—is starting to moderate. As a result, firms have more time to work through order backlogs and increase production. Many economists say inventory replenishment should boost output in the coming quarters.

A strong comeback in consumer demand this spring has been a double-edged sword for many businesses. Sales have boomed, allowing companies to recover losses, but growth has been so rapid, some have found it difficult to keep pace.

When many people got vaccinated earlier this year, they started flooding into Factory Hair Seattle to get their hair cut, said Denise Rivera, the salon’s owner. “It just exploded,” she said. “I’ve been through a recession and seen the economy come back, but never anything like this.”

As business soared, some stylists became mentally fatigued, and some said they couldn’t take any more clients. Ms. Rivera added two stylists to her staff of six to try to keep up with the onslaught of customers.

The salon also raised prices, in part to slow growth a bit to a more manageable level, said Ms. Rivera. Haircuts, which include a shampoo and a blowout, cost an average of $60 to $70, up by $5 from a year ago, she said.

Consumer prices rose 5.4% in June from a year before, the fastest pace since 2008, the Labor Department reported. As overall economic growth eases, price increases could cool as well. Economists surveyed by The Wall Street Journal in July see inflation measured by the department’s consumer-price index easing later this year, to 4.1% in December from a year earlier, and 2.5% by the end of 2022.

Overall, economists expect growth to remain strong, barring a sharp re-emergence of virus cases and related restrictions and fear. Respondents to the WSJ survey forecast the economy to grow 7% in the third quarter before drifting down to a 3.3% rate in the second quarter of 2022.

When the pandemic hit, sales at flatware maker Sherrill Manufacturing Inc. began doubling.

“The restaurants all shut down, so people were cooking for themselves, many of whom had never cooked anything beyond mac and cheese,” said Greg Owens, Sherrill’s chief executive. “They wanted something nicer on their table.”

Sales have continued to grow solidly but have cooled from the red-hot pace logged throughout much of the pandemic. Mr. Owens said the spending boost from government stimulus money has faded, and people are shifting their spending toward services such as restaurants amid reopenings.

“That has certainly created less of a demand for people sitting at home going, ‘Our plates are kind of old and I don’t really like them,’ or ‘Our flatware is dated,’” he said.

Still, Mr. Owens expects sales to remain strong. His company manufactures flatware in the U.S, and he said many individuals are increasingly interested in buying American-made products because of the limited availability of many imported goods during the pandemic.

At Factory Hair Seattle, business just recently started to level off, though the salon remains busy. The salon is seeing an influx of men coming in to tidy up—but still maintain—their longer pandemic hair, Ms. Rivera said.

“They’re like, ‘I’m still not going to be going back into my office until September, October,’ ” she said. “They don’t want to go back to this short, high-and-tight corporate look.”

Write to Sarah Chaney Cambon at sarah.chaney@wsj.com