The majority of magma erupted at the Earth's surface is produced by melting of mantle rock at depths of less than 50 km. Some magmas are also produced by melting of crustal rocks at shallower levels (less than30 km). The Earth's interior is very hot, but it is mostly solid because of the high pressures at depth in the Earth.The main process of melting occurs when mantle rock rises toward the surface, such as at mid-ocean ridges, and undergoes depressurization melting, without the addition heat.      
View animation of melting
Photo courtesy of USGS
  Magma can also be generated by melting due to the lowering of the mantle melting temperature because water and other volatile components have been introduced into the mantle. The occurs chiefly in subduction zones where oceanic lithosphere is descending back into the mantle (see figure to left). The oceanic lithosphere carries with it water in sediments and altered rocks.  
Magma Composition
The chemical composition of magma reflects the composition of the rocks involved in the melting process. There is a large range of magma compositions erupted at the Earth's surface. The most common magma is called basalt, a silicate liquid with a SiO2 content of about 50%. In general, the SiO2 content of magma varies from about 45-75%, with low-silica magmas referred to as mafic and high silica magmas, felsic. There is a continuum in the composition of magma types between these two end-members.