This is probably going to be a longer answer than you want but here you go.
The origin of the earth can be described by the nebular hypothesis. Pretty much there was a supernova (a star exploded) which produced clouds of gas and dust. These clouds of gas (mostly hydrogen and helium) get compacted and denser as gravity pulled them into one another. The center of this cloud becomes hotter and hotter as more of the dust gets pulled into the center. It eventually starts to rotate and we have a protoplanetary disk. Again, most of the mass gets pulled into the center due to gravity so we essentially have a a flattened disk of matter with a central bulge. This bulge is primarily made up of hydrogen and helium. The hydrogens get so compressed they start colliding and nuclear fusion takes place turning the hydrogen into helium and the star lights up forming our sun. When this happens solar wind pushes the lighter elements away from the center and out into space leaving behind the rocky condesnef materials towards the center and lighter elements towards the outside. This is why we have out gas rocky planets towards the center and our gas planets near the outside.
Now onto the formation of earth. The rocky interior of the solar system begin to collide with eachother forming protoplanets. Earth earth was constantly bombarded with asteroids leading to a lot of internal heat (due to kinetic energy). The earth was essentially a molten ball of rock which allowed denser elements like Fe to sink to the middle while lighter elects like silica to stay at the top. This makes up the composition of earth today. It consists of a solid iron core with a liquid outer core also primarily made up of iron (the movement of this outer core also makes up the earths magnetic field). Then we have our mantle made up primarily of elements such as Fe, Mg, Si, O. Then finally we come to the lithosphere and crust and we get more lighter elements such as Si, Ca, K, Na.