The solar system formed from a large rotating cloud of dust and gas called the solar nebula. As the nebula collapsed, a section broke off to form the sun at the center, with planetesimals - small particles that formed the planets - orbiting around it. Over time, gravity caused the particles to come together and form the eight planets in orbits around the growing sun. The inner planets are rocky, while the outer planets are gas giants.