Richard Palmer stood outside the White House and forgot for a moment the sense of foreboding he said he has felt about his country as the contentious 2016 presidential race has unfolded.

Instead, he marveled at the diversity of the large crowd coming and going in front of Washington’s most famous address on the morning of the Fourth of July: a California couple in American flag T-shirts volunteering to photograph an Asian family; a schoolteacher from Florida reveling in the idea that he was standing where Abraham Lincoln once lived; a British couple wearing crowns matching the one atop the Statue of Liberty.

“It gives you a renewed sense of hope,” said Palmer, 51, a salesman visiting from West Virginia with his family. “It’s a scary time. I hate what’s going on. But coming down the street here and seeing all this, I thought, ‘Maybe everything will be good.’ There are so many nationalities here, and people seem to care about things.”

In a year of bitter politics and terrifying episodes of domestic and international terrorism, Americans gathering for July 4 in the nation’s capital embraced the holiday as a respite from the grind of unsettling news.

Beneath slate-gray skies and with temperatures in the low 70s, their greatest challenge was intermittent rain and, as the afternoon wore on, the threat that the annual fireworks on the Mall would be delayed or postponed.

Americans celebrated Independence Day and attended parades across the country amid heightened security concerns after a wave of terrorist attacks in Turkey, Bangladesh and Iraq in recent days. (Reuters)

The weather did cancel the annual Independence Day celebration that the White House hosts on the South Lawn. A smaller celebration was held indoors.

But out on the Mall, the rain at last abated, and the fireworks show went on, although shielded a bit by the low-hanging clouds.

Much of the glare of the explosive display appeared hidden, and the typical “oohs” and “aahs” seemed a bit muted.

But it was still worth it, said Florida native Bobby Desmond, 23. “It’s definitely something I’ve always wanted to do,” he said.

A television broadcast of the festivities showed a fireworks display different from what was seen on the Mall. Representatives of “A Capitol Fourth,” which aired on PBS, said that because of the overcast skies, the program showed a combination of the best fireworks from this year and previous years. A spokesman added: “It was the patriotic thing to do.”

Earlier, on the grassy slope between the Washington Monument and the National World War II Memorial, Nick Nguyen strung a tarp between branches to avoid the pouring rain at 4 p.m.

“We’re prepared this year,” said Nguyen, 44, who came with his wife and two children from North Carolina. Last year they were soaked in another downpour.

Rafael Rodriguez, 15, sought refuge on a bench by an information booth on the West Lawn of the Capitol. He had driven from Florida with his family on Friday to experience the Fourth in Washington.

“It’s more special,” he said. “This is where stuff gets done.”

Amid afternoon showers, people at the Smithsonian’s Folklife Festival on the Mall popped open umbrellas, donned rain jackets and crowded under tents. Some talked of trying a movie, a restaurant, even an early trip home. Long lines formed to enter the National Air and Space Museum.

The downpour didn’t stop the Snider family:Gathering on the Mall for the fireworks is a tradition for their Laurel, Md., clan.

“We’ve seen worse before,” said Jim Snider, 63, who has celebrated the Fourth on the Mall every year since 1976. His cigar stayed lit despite the rain. His daughter ­Jamie and her best friend giggled as they splashed on the grass and kicked a bright pink soccer ball.

In front of the White House, Jay Statzer, 50, who drove from Nebraska, said July 4 is an opportunity to celebrate time-honored American rights, such as free speech, and to promote cherished causes. In his case, the cause was legalizing marijuana. He said he planned to speak at an annual pro-pot rally in Lafayette Square.

“If cannabis were legal, we’d have a lot calmer people,” said Statzer, who wore a T-shirt emblazoned with a cartoon of Bill Clinton, joint between his lips, under the words, “Inhale to the Chief.”

Reed Turner, 54, a tourist from California, wore a pullover shirt with the image of the American flag and words from the Declaration of Independence. He said the day made him appreciate American history and wish to block the noise of contemporary events.

“You have to separate it because today is about patriotism and the birth of something amazing,” Turner said. “Otherwise, you’ll drive yourself nuts.”

Earlier in the day, hundreds of spectators assembled outside the National Archives to listen to a dramatic reading of the Declaration of Independence.

In star-spangled fedoras, socks and fanny packs, many spoke Spanish, Japanese and French. One woman used Facetime to broadcast the performance to a friend, shouting in Chinese above the buzz of the snare drums.

Gazing around, Emmy and Sam Berger said they were inspired by the diversity.

“It’s the best country in all of the world,” said Emmy, 79, who moved to the United States from Chile in 1966. “Though there are a lot of problems, people are very compassionate and loving. The people are what makes the difference.”

Around noon, crowds lined up along Constitution Avenue NW for a July 4 parade featuring a heavy police presence. Many onlookers kept one eye on the marching bands, another on the gray skies.

Despite recent terror attacks and a mass shooting, many at the parade said they were not concerned about their safety.

“I’ve been all over the world, that don’t bother me,” said Jim Hunnicut, 71, a Navy veteran who lives at the Armed Forces Retirement Home in the District.

Scott and Sharon Weiss, also District residents, were similarly unfazed by security concerns.

“I have a lot of hope,” said Sharon, 56, resting atop her bicycle at the corner of 10th Street NW to observe the parade. “I have faith that our country will do the right thing.”

Julie and Brian Wagoner, who traveled from Indiana, said the elections seemed to have brought out more patriotism in many people.

“It’s awesome to see all the red, white and blue,” Julie, 45, said.

As dozens of policemen walked by in bright yellow vests, she said she was glad to see so much law enforcement. “I’m not concerned about anything happening, but that makes me feel better,” she said.

Away from downtown, Mayor Muriel E. Bowser was among local politicians who marched in the Palisades neighborhood’s annual parade. On Capitol Hill’s Barracks Row, along Eighth Street SE, community leaders hosted another parade, as did the city of Takoma Park in Montgomery County.

But the main attractions were along the Mall, where tourists snapped photos in front of the city’s iconic spots.

“Everything is so big here — the flags are big, we don’t have that like you do,” Laura Marlow, 19, a visitor from England, said outside the White House. She and a friend, Tom Walsh, wore socks showing stars and Statue of Liberty crowns.

“Patriotism is nothing in Britain,” she said. “We just love American patriotism.”

A few feet away, Scott Houchins, 46, a music teacher from Florida, said he was swept away by Washington’s historic grandeur.

“To be where presidents have walked — that’s cool to me,” he said, in a T-shirt with the Superman logo. “For someone who’s into history, this is the place to be, and on this day especially.”

Briana Pack, 18, a waitress from Tennessee, stood smiling under a large sign that read “TRUMP.” It was at the Old Post Office, which the Republican presidential candidate is developing into a hotel.

“Take a picture — do it!” she ordered her boyfriend.

“I like Trump — he’s very straightforward, he gets right to the point,” she said, as boyfriend, Jerry Tipton II, 19, smirked and said he backed Bernie Sanders.

Tipton’s father, a construction worker and Trump supporter, said politics was the least of his concerns at that moment.“Where’s the nearest McDonald’s? We’re hungry,” he said. “You can’t get any more American than that.”

LaVendrick Smith, Emily Yahr, Michael Smith and Martin Weil contributed to this report.