Igneous rocks are formed by cooling and melting magma underground or on the Earth's surface. There are three main types of rocks: igneous rocks, which are formed by cooling magma; sedimentary rocks, which are formed by the compression of sediment; and metamorphic rocks, which are formed by the transformation of pre-existing rocks by heat, pressure, and chemical reactions.