It was five billion years ago. A giant cloud of matter in our own galaxy, the Milky Way, condensed under its gravity, exploding in nuclear fusion.
This fusion released what we call sunshine. Very, very, very hot sunshine. And the newly formed star was our Sun. It drew in most of the surrounding matter, but some escaped. And some of this material clumped together, settling into a protoplanetary orbit.
Tasty morsels of gas and rock
Those chemically rich leftovers orbiting our young Sun were stewing with all the ingredients to form the planets in our Solar System.
The intense heat of the young Sun drove away most of the lighter hydrogen and helium elements — 99% of the leftovers — the furthest. These eventually condensed to form the gassy outer giants — Jupiter, Saturn, Uranus, and Neptune. The tiny bit of heavier elements that remained made up the rockier Mercury, Venus, Earth, and Mars.
Through a combination of gentle collisions and gravity these atoms and molecules began attracting other like-sized material. Over millions of years, they gradually shaped themselves into solid planetesimals, and later protoplanets with their own unique orbits.
Astronomers call all this smashing and joining together accretion. After 10 to 100 million years of this banging, eight spherical, stable planets remained. Our Solar System spun into place.