Rocks come from magma, which is the molten material found within the earth. When magma cools, either above or below the earth's surface, it crystallizes and forms the igneous rocks that can later be changed into metamorphic or sedimentary rocks. Magma, which can be considered molten rock, is referred to as lava when it reaches the earth's surface.
The igneous rocks initially formed from cooled and crystallized magma can eventually be weathered down into fragments by the forces of erosion. They then become sedimentary rocks through the additional processes of compaction and cementation. Both igneous and sedimentary rocks can be transformed into metamorphic rock when subjected to pressure and temperature conditions other than those which originally formed them. Heat is produced by the friction generated by movements of Earth's tectonic plates, and the creation of mountains creates pressure. An intrusion of magma into surrounding rock can also be a source of heat. Overall, the temperatures and pressures needed to produce metamorphic rocks are much greater than those found on the earth's surface.
Each of the three major classes of rock can be transformed into one of the other classes through the continuing processes of heat, pressure and erosion. This ongoing transformation of rocks is referred to as the rock cycle.