Magma is nothing but a mixture of elements like potassium, silica, sodium, iron, etc. and also contains gases such as carbon dioxide, sulfur dioxide, etc. Since it is less dense than the surrounding rocks in the earth's crust, it begins to rise to the surface of the earth.