Why Does Root Beer Foam So Much?
Root beer was originally made partially with sassafras root bark (and sarsaparilla, etc) which naturally foamed.
Carbonated beverages form bubbles - in seltzer water the bubbles dissipate quickly. When flavoring ingredients are added, the bubbles frequently form a longer lasting foam.
If you add a substance that acts as a 'surfactant,' (lowers the surface tension) the bubbles will last even longer. Similar to dish washing detergent foam. Sassafras naturally acts as a surfactant - the dried, ground leaves are called gumbo file, or just file, and are used to thicken Creole gumbo. The same mucilaginous properties that thicken gumbo, made root beer form a long lasting foam.
(The amount and type or carbonation - natural or artificial - also affects the size of the bubbles).
Sassafras root bark contains safrole, which the FDA determined was a potential carcinogen and banned in the 1960s. Root beer manufacturers turned to other flavoring combinations as a substitute (sarsaparilla, ginger, juniper, wintergreen, licorice, anise, cinnamon, lemon oil, orange oil, cloves, vanilla, and artificial flavors, in various combinations.). But none of these have the same foam enhancing qualities as sassafras root bark. So other surfactants were added, including an extract from the yucca plant.
The particular brands of root beer that foam a lot do so because that's the way the manufacturers make it - foaming characteristics have become part of the marketing campaigns.
Not all root beers foam the same - for instance Barq's root beer is more highly carbonated and Dad's root beer has more long lasting foam.