By Dave Sebastian and Sharon Terlep

Walmart Inc. and Kroger Co. will require customers to wear face coverings inside all their U.S. stores, joining a growing chorus of big businesses and state leaders deciding that masks are needed to battle the surge in coronavirus cases and calling for a national policy.

The retail giants, which operate more than 8,000 stores across the country, said they were adopting their own mask requirements to protect their staff and customers. Walmart said a lack of federal rules had left it with a patchwork of local regulations. "We know this is a simple step everyone can take for their safety and the safety of others," it said.

They join major U.S. airlines and a growing number of governors, even those who were initially hesitant to do so, in adopting mask requirements to stop the spread of the respiratory disease, which has killed more than 136,000 in the U.S.

Walmart and Kroger have kept their stores open through the pandemic and required workers to wear masks, but like most retailers they previously followed local guidelines for shoppers. "We recognize additional precautions are needed to protect our country," Kroger said.

Other chains made similar moves after Walmart's announcement Wednesday, including Kohl's Corp., which operates about 1,000 department stores, and Panera Bread, which has about 2,000 restaurants. Best Buy Co. and Starbucks Corp. had previously adopted mask rules that kicked in on Wednesday.

There is widespread scientific and medical consensus that face masks are critical in slowing the virus's spread. The Centers for Disease Control and Prevention recommends that everyone wear a face covering in public, especially indoors and when social distancing isn't possible. President Donald Trump, who wore a mask in public for the first time this weekend, has resisted calls for a national mandate. The White House Coronavirus Task Force has left any mask mandates to states.

An increasing number of states, including hard-hit California and New York, mandate masks in public but about half of states don't, including Florida, where there has been a surge in cases, and Walmart's home state of Arkansas. Many local governments have mandates in states where they aren't required.

In early July, amid rising case totals, Texas Gov. Greg Abbott, who once prohibited local officials from requiring masks, did an about face, ordering most Texans to start wearing them. Alabama Gov. Kay Ivey on Wednesday said she would be implementing a statewide mask order.

The differing rules have prompted business leaders to call on the White House and state leaders to adopt a national mask policy. "Issuing voluntary guidance on masks is insufficient to protect public health" and risks continued community spread and a new round of shutdowns, the U.S. Chamber of Commerce, National Retail Federation and other business groups wrote in a July 2 letter to the White House and governors.

"Retailers are protecting the health and safety of communities they serve," the NRF said in a statement issued Wednesday. "Our elected leaders need to set politics aside and follow their example." The industry group called on all retailers to adopt nationwide mask policies, saying Walmart's decision was a tipping point in the debate.

U.S. airlines began requiring customers to wear masks in May. Initially, enforcement was lax, but over the last month airlines have tried to step up enforcement, pledging to ban passengers who refuse to comply at least until the pandemic passes. Some aviation unions have said this doesn't go far enough and want a federal rule requiring masks on planes.

Delta Air Lines Inc. Chief Executive Ed Bastian on Tuesday stopped short of calling for new regulation, but said it would be helpful if the federal government would more strongly encourage people to wear masks throughout their daily lives, including during travel.

The United Food and Commercial Workers International Union, which represents 1.3 million workers in grocery, retail and other industries, has also called for a national mask mandate. "With governors in the majority of states refusing to make masks mandatory, millions of Americans are needlessly being put in danger every day," said Marc Perrone, the UFCW International president.

Nearly three-quarters of voters in a new Wall Street Journal/NBC News poll said they always wear a mask while shopping, working or when they are around people outside their homes, an 11-percentage-point increase from last month. The share of Trump supporters who say they always wear masks climbed 15 points since June, from 39% to 54%.

Businesses have been caught in the middle and taken it upon themselves to set nationwide masks requirements. Costco Wholesale Corp. took a lead on the issue and has required masks for shoppers since May, making it a target for critics of the policies. Walmart's mask rule begins July 20 for its stores and Sam's Clubs locations, while Kroger's starts July 22.

About two-thirds of Walmart's 5,000 stores are in areas with mask mandates. In those places, "virtually everyone either brings a mask or readily complies with the requirement, and we anticipate that to happen in other areas as well," said Dacona Smith, Walmart's chief operating officer, and Lance De La Rosa, Sam's Club chief operating officer.

Earl Lagorin, an 81-year-old Colorado resident, said he stopped shopping at one Walmart outside Denver because he didn't find the wearing of masks to be adequately encouraged. "I think it's wonderful if they can enforce" the mask policy, he said.

Most major companies, from big-box retailers to pharmacy chains, require employees to wear masks and ask shoppers to wear them in places where state or local governments say they are mandatory. Some of those companies prohibit patrons from entering without a mask, while others request customers wear one but will still allow them in if they refuse.

Tony Alfonso, a 46-year-old North St. Paul, Minn., resident, said he doesn't believe in the effectiveness of masks and won't be going to Walmart after the new requirement is in effect. He said he would abide by a store's mask policy if he needs to get an item that can't be found elsewhere. "A business can do what they want obviously, but I'm just opposed to it being mandated for people," he said.

Walmart said it would have staff members at store entrances to remind visitors who aren't wearing a mask and hand out free masks to those who didn't bring one. It will make some exceptions to the requirement. "Our associates will be trained on those exceptions to help reduce friction for the shopper," Messrs. Smith and De La Rosa said.

Stores will have a single entrance to ensure the requirement's consistency.

The Walmart executives said people have different opinions on the topic but the company "recognizes the role we can play to help protect the health and well-being of the communities we serve by following the evolving guidance of health officials like the CDC."

Kroger, whose chains include Fred Meyer and Harris Teeter, said customers with medical conditions may not be able to wear a mask, and it encourages them to wear a face shield or facial covering instead. The supermarket operator asks those who are unable to do so to use the grocer's e-commerce services for pickup or delivery.

--Allison Sider contributed to this article.

Write to Dave Sebastian at dave.sebastian@wsj.com and Sharon Terlep at sharon.terlep@wsj.com