Hydrogen peroxide (H2O2) is something you can buy at the drug store. What you are buying is a 3-percent solution, meaning the bottle contains 97-percent water and 3-percent hydrogen peroxide. Most people use it as an antiseptic. It turns out that it is not very good as an antiseptic, but it is not bad for washing cuts and scrapes and the foaming looks cool.
The reason why it foams is because blood and cells contain an enzyme called catalase. Since a cut or scrape contains both blood and damaged cells, there is lots of catalase floating around.
When the catalase comes in contact with hydrogen peroxide, it turns the hydrogen peroxide (H2O2) into water (H2O) and oxygen gas (O2).
H2O2 --> H2O + O2
Catalase does this extremely efficiently -- up to 200,000 reactions per second. The bubbles you see in the foam are pure oxygen bubbles being created by the catalase. Try putting a little hydrogen peroxide on a cut potato and it will do the same thing for the same reason -- catalase in the damaged potato cells reacts with the hydrogen peroxide.
Hydrogen peroxide does not foam in the bottle or on your skin because there is no catalase to help the reaction to occur. Hydrogen peroxide is stable at room temperature.
Here are some interesting links: