Maziwa iko na fat and water. When heat is applied, the same fat collects at the top and forms a layer trapping the water segment below. Hot air bubbles to the top pushing through the top upper layer.
In cappuccinos the same concept is applied to create a foam. A wand is applied to heat the entire milk but then it's moved into the top upper layer dancing in and out to introduce air and create a bigger layer of foam.