Planets are formed from the dust and gas left over after a star is born.
This dust and gas come together to form small particles called planetesimals.
Planetesimals collide and stick together to form larger bodies called protoplanets.
These protoplanets continue to grow by colliding with other protoplanets and planetesimals.
Eventually, the protoplanets become large enough to have their own gravity and become planets.
The inner planets, like Earth, are made up of rock and metal because they formed closer to the sun where it was hotter.
The outer planets, like Jupiter, are made up of gas and ice because they formed farther from the sun where it was colder.
Some planets, like Earth, have moons that formed from the same process as the planets themselves.
The process of planet formation can take millions of years.
For more such interesting stuff, click on the link given below