At depth in the Earth nearly all magmas contain gas dissolved in the liquid but gas forms a separate vapor phase when pressure is decreased as magma rises toward the surface of the Earth. This similar to carbonated beverages which are bottled at high pressure. The high pressure keeps the gas in solution in the liquid, but when pressure is decreased,like when you open the can or bottle,the gas comes out or solution and forma a separate gas phase that you see as bubbles. Gad gives magma their explosive character,because volume of gas expands as pressure is reduced. the compositions of the gases in magma are
Mostly H2O