To know how planets form, we first have to know a little about how stars form.
Stars form from giant clouds of cold gas; when this gas gets cold and dense enough, it will start to collapse inward under its own weight. When it does this, the cloud will start to rotate a little. The more the cloud collapses, the more it rotates, until instead of a blobby cloud of gas, you have a relatively thin, rotating disk of gas. This is the same phenomenon that happens if you spin yourself in your chair with your arms and legs sticking out; if you pull your arms and legs in, you'll rotate faster.
So, you have a dense disk of gas that's rotating. Most of the mass in the center of the disk will help form an object at the very center, which, if it's big enough, will start burning hydrogen and officially become a star. But there's still a lot of gas hanging around in the disk that didn't go into the star because it was too far out to go into the central object. The leftover gas and dust out further from the star is still relatively cold, and cold gas likes to collapse. (This is how we got the star in the first place!) There's usually not enough mass in the rest of the disk to form another star, but it can still collapse into little chunks of material. These new chunks of stuff orbiting around the star will crash into each other and either knock each other apart (meaning this growing process has to start over) or they'll glue themselves together and become one larger lump. This lump can keep on growing by having smaller bits of the disk run into it, and eventually you have something that has run out of things to run into in its own orbit. This is your new planet!
Because all the planets are formed out of the main disk of gas and dust that was rotating around the star at the start, all the planets should orbit around the star in the same way, and should be pretty close to orbiting in a single plane around the star. Our solar system behaves this way; every planet goes around the sun in the same direction, and the main 8 planets are all in a very thin plane. We can see this ourselves in the night sky - all the planets always appear along a single arc in the sky: the ecliptic.
Sign up for the mailing list for updates & news straight to your inbox!