In planetary science, planetary differentiation is a process by which the denser portions of a planet will sink to the center; while less dense materials rise to the surface. Such a process tends to create a core, crust, and mantle.
When the Sun ignited in solar nebula, hydrogen, helium and other volatile materials were evaporated in the area near the Sun. The solar wind and light pressure forced such material of low density away from the Sun. Rocks, and material trapped in them, accumulated in protoplanets.
Early protoplanets had more radioactive elements, the quantity of which has been reduced over time due to radioactive decay. Heating due to radioactivity, impact, and gravitational pressure melted parts of protoplanets as they grew toward being planets. In melted zones their heavier elements sank to the center; while lighter elements rose to the surface. Composition of some meteorites show that differentiation took place in some asteroids.
When protoplanets accrete more material, the energy at impact causes local heating. In addition to this temporary heating, when a body is large enough then the gravitational force upon a new lump on the surface will create pressures and temperatures which are sufficient to melt some of the materials. This allows chemical reactions and density differences to mix and separate materials, and soft materials to spread out over the surface.
On Earth, a large piece of molten iron is sufficiently more dense than continental crust material that it can force its way down through the crust to the mantle. In the outer solar system similar effects may take place but the materials may be hydrocarbons such as methane, water ice, or frozen carbon dioxide.
Note that some materials may differentiate to regions due to their chemical affinities rather than their densities, "carried along" by other materials that they're associated with; the uranium in Earth's crust is an example.
Materials with a high density tend to sink through lighter materials. This tendency is affected by the relative structural strengths, but such strength is reduced at temperatures where both materials are plastic or molten.
Lighter materials try to rise through material with a higher density. On Earth, salt domes are salt deposits in the crust which rise through surrounding rock. Diapirs of other materials exist, and sometimes appear on the surface as mud volcanos.
On the Moon, a material formed on the surface which is believed to have formed due to its components being incompatible with the cooling molten material. The material is high in potassium (periodic table symbol K), rare earth elements, and phosphorus and is often referred to with the abbreviation KREEP. It also is high in uranium and thorium.
On Earth, when magma rises above a certain depth the dissolved materials may crystallize at certain pressures and temperatures. The resulting solids remove various elements from the melt, and melt which returns to the mantle is thus depleted of those elements.
The Soret effect is displayed when material is unevenly heated. Lighter material migrates toward hotter zones and heavier material migrates toward colder areas.
Differentiation through collision
The Earth's Moon seems to have been formed out of material splashed into orbit by the impact of a large body into the early Earth. Differentiation on Earth had probably separated many lighter materials toward the surface, so the splash probably removed many light materials from the planet. The Moon's density is substantially less than that of Earth. The Earth's crust is probably much thinner than it otherwise would have been, and plate tectonics functions on this planet differently than it could on Venus or Mars.
Density differences on Earth
On Earth, such processes created a surface density of 3000 kg/m3, while the average density of the planet is 5515 kg/m3.