Igneous rocks form when magma cools and hardens either underground or at the earth's surface. Their texture and composition depend on the elements in the magma and cooling conditions. Sedimentary rocks form through the compaction or cementation of sediments and include clastic, chemical, and organic types. Metamorphic rocks form when existing rocks are subjected to heat and pressure, causing changes in their texture and mineral composition. Rocks continuously cycle between these three types through geological processes of melting, cooling, weathering, erosion, deposition, and metamorphism.