Way back before the solar system was formed it was just a huge cloud of dust and gas floating in space.
The natural attraction of gravity caused the dust to start whirling around a central lump.
This lump collected more and more matter until it became so large that the force of its own gravity crushing down on its middle caused the center to ignite in a nuclear fire. Our sun was being born!
The remaining cloud of dust was now spinning around the sun. But gravity was still in operation inside the dust cloud. Over time the tiny flecks of cloud began to clump together once more, making marble-size lumps, then basketball-sized lumps...all the way up to planet-sized lumps.
Over a certain size the biggest lumps had enough gravitational attraction on their own to mop up the remaining dust and gas by adding it to themselves. One of those lumps, still spinning around the sun, is where you are now standing. We call it Earth!
So why did the planets form exactly where they are in relation to the sun, instead of somewhere else?