Why does foam form?
Short answer
Small gas bubbles enter a liquid and are temporarily stabilized by surface tension and surface-active substances.
How it works
Soap changes surface behavior and helps bubbles last. Bubble size and lifetime also depend on viscosity and temperature.
Key point
The practical point is this: Bubble size and lifetime also depend on viscosity and temperature.