According to the National Oceanic and Atmospheric Administration, sea foam forms when the organic and artificial matter in the ocean is agitated by wind and waves.
Algal blooms are one common source of thick sea foams. When large blooms of algae decay offshore, great amounts of decaying algal matter often wash ashore. Sea foam then forms as that organic matter is churned up by the surf, according to NOAA.
"Most sea foam is not harmful to humans and is often an indication of a productive ocean ecosystem," according to the agency. "But when large harmful algal blooms decay near shore, there are potentials for impacts to human health and the environment."
During blooms along the Gulf Coast, popping sea foam bubbles can allow for toxins in algae to become airborne.
"The resulting aerosol can irritate the eyes of beach goers and poses a health risk for those with asthma or other respiratory conditions," according to NOAA.
Footage obtained by the Associated Press showed waves crashing in over Tossa de Mar's beach, with floodwater moving past shoreline restaurants and businesses on its way to the old town center.
According to NOAA, scientists studying seabird die-offs along the West Coast in 2007 and 2009 found that a soap-like foam from decaying algae bloom had removed the waterproofing on feathers, making it harder for birds to fly.
"This led to the onset of fatal hypothermia in many birds," according to the agency.