According to a 2011 paper by several Austrian scientists called “Foam in the Aquatic Environment,” the answer is–somewhat unhelpfully–yes, and yes. In order for foam to form, you need air, water, and a key third ingredient called a “surfactant”–a kind of sticky molecule that clings to the surface between water and air. This surfactant ingredient can come from a lot of places; human-made sources include fertilizers, detergents, paper factories, leather tanneries, and sewage. But surfactants also come from the proteins and fats in algae, seaweed, and other marine plant life.
There are lots of different molecules that can act as surfactants, but they all have one thing in common: one end of the molecule is hydrophilic (attracted to water) while the other end is hydrophobic (repelled by water). When a bunch of surfactant molecules get mixed together with plenty of water and air, they all want to line themselves up right at the boundary, with one end (hydrophilc) facing the water and the other (hydrophobic) facing the air. They’ll even line up back to back, so that the hydrophilic ends are pointed at each other, with a thin layer of water in between. That thin layer of water takes the shape of a sphere, because a sphere requires the least energy of any shape, and voila, it’s a bubble. Things get slightly more complicated when there are many bubbles packed together–as you might have noticed while taking a bubble bath as a kid (or as an adult), foamy bubbles aren’t perfect spheres–but the basic idea is the same. It’s all about the surfactant.
“Foam in the Aquatic Environment” mentions several reports of “unusual quantities” of foam forming near large algal blooms. “Great amounts of carbohydrates and proteins are released by the mucilaginous cell colonies,” the authors write, giving rise to “copious amounts of viscous foams and mucus in the water column.”
When the algal proteins or carbohydrates get close to shore, the waves “act like a big blender,” explains Raphael Kudela, a marine ecologist at the University of California, Santa Cruz. “Physical agitation breaks them up and lets them reform,” as foam; the foam is then swept ashore, where it accumulates.
In any amount, natural sea foam is usually harmless–but, as marine biologists in California discovered a few years ago–not always.