Scientists have two main theories that explain how the world was created. Most believe in the core accretion theory, though a few believe in the disk instability theory. The core accretion theory makes more sense when it comes to the creation of small, rocky planets such as Earth.
The beginnings of the world reach back to about 4.6 billion years ago in a solar nebula. This is a cloud or ring of dust and gas that over time began to implode due to its own gravity. As the cloud collapsed, it began to spin. Eventually, the sun ignited in the middle of the cloud.
When the sun ignited, the dust around it began to form clumps that grew larger and larger. The sun's own wind blew away lighter elements such as hydrogen from the clumps closest to it and left heavy elements to continue to stick together until small, rocky worlds such as Earth formed. The Earth's core was formed first, then lighter materials coalesced around it to make up the planet's mantle and crust.
Because the solar wind didn't affect the young planets that were farther away, these planets' lighter elements were left relatively unscathed. Scientists believe this created the gas giants such as Jupiter and Saturn, whose thick atmospheres are dominated by hydrogen.