Surface tension is the tendency of the surface of a liquid to minimize its surface area. When a liquid is agitated, the surface tension at the liquid-air interface can cause the formation of bubbles.
The pressure of the gas within the foam bubbles also contributes to the stability and size of the foam. Higher gas pressure can lead to the formation of larger, more stable foam bubbles.
Surfactants are molecules that lower the surface tension of a liquid, allowing it to spread more easily. In the context of foam, surfactants help stabilize the bubbles and prevent them from coalescing.