The semifluid or hot fluid substance within or below the crust of the Earth from which lava and other igneous rock are produced by cooling is known as magma.
The temperature and pressure elevate with depth, finally reaching to a level wherein the strongest rock is melted, transforming into magma. When the magma comes into contact with water, it instantly gets transformed into a rock, that is, the outside solidifies briskly, and the inside of it gets cold.