This is a result of the way the solar system formed from a spinning cloud of gas and dust. As the cloud collapsed, it spun faster and faster, and eventually, the material flattened into a disk. The planets formed from this disk, and they inherited its original direction of rotation.
There are some exceptions, like some moons that orbit in the opposite direction (retrograde motion). This can happen if the moon is captured by the planet's gravity or if it formed elsewhere and was later pulled into orbit.