A cloud collapses to form a star and disk. Planets form from this disk. According to our current understanding, a star and its planets form out of a collapsing cloud of dust and gas within a larger cloud called a nebula.
The Earth is thought to have been formed about 4.6 billion years ago by collisions in the giant disc-shaped cloud of material that also formed the Sun. Gravity slowly gathered this gas and dust together into clumps that became asteroids and small early planets called planetesimals.