A dense hydrogen-rich cloud of gas and dust contracts under gravity. As the gas gets compressed, its temperature increases and the dust cloud begins to spin. A protostar begins to form at the centre of this spinning dust cloud. Nuclear fusion starts, and a star is born. The planets begin to form from the swirling dust clouds around the star.
Gravity is greater closer to the star. Most of the dense material in the dust cloud is attracted strongly and ends up here.
The inner four planets (Mercury, Venus, Earth, and Mars) are rocky and have solid surfaces that can be walked on.
When the solar system formed, rocks (and other dense, heavy materials in the dust cloud such as iron and uranium) tended to gather closer to the Sun, and these materials combined together to form the inner planets.
The outer four planets (Jupiter, Saturn, Uranus, and Neptune) are called gas giants. When the solar system formed, gaseous substances gathered together further away from the Sun and formed the gas giants.