The universe was once a microscopic dot, called a singularity. Because everything in the universe was condensed into this singularity, it was very hot and dense.
The singularity, full of energy, became unstable and exploded 13.82 billion years ago, resulting in quarks and electrons going everywhere. After the explosion, everything that was condense, was now unraveling, causing everything to cool down.
The cooling of all the quarks allowed them to fuse together to form protons and neutrons. The protons and neutrons then combined with electrons to form elements like hydrogen and helium. Gravity allowed for hydrogen and helium gas to come together and form the first stars.
About 4.6 billion years ago, gas and dust from the explosion of the singularity caused the formation of a spinning interstellar cloud (disk). The cloud became dense as a result of gravity. As more debris from the explosion collided, the gas became very hot and dense to form the sun.
Around the same time, the sun's spinning disk became cool, causing different substances to condense into a liquid or solid form. These different substances caused the formation of the earth and moon.
The different substances also lead to the formation of other planets in the Milky Way Galaxy like Mars, Saturn, and Jupiter.