Sea foam forms when organic matter in the ocean is churned up by wind and waves.
You may not think this to look at it, but seawater contains salts, proteins, fats, dead algae, and a vast amount of other tiny bits of organic matter. As these components are agitated by wind and wave action, foam will eventually form.
Occasionally, giant algae blooms will occur offshore and a large amount of decaying algae will wash in. When that water combines with the heavy surf action generated by storms or rough seas, a light, fluffy froth may result.