George Spagna, chair of the physics department at Randolph-Macon College, explains.
Stars and planets form in the collapse of huge clouds of interstellar gas and dust. The material in these clouds is in constant motion, and the clouds themselves are in motion, orbiting in the aggregate gravity of the galaxy. As a result of this movement, the cloud will most likely have some slight rotation as seen from a point near its center. This rotation can be described as angular momentum, a conserved measure of its motion that cannot change. Conservation of angular momentum explains why an ice skater spins more rapidly as she pulls her arms in. As her arms come closer to her axis of rotation, her speed increases and her angular momentum remains the same. Similarly, her rotation slows when she extends her arms at the conclusion of the spin.
As an interstellar cloud collapses, it fragments into smaller pieces, each collapsing independently and each carrying part of the original angular momentum. The rotating clouds flatten into protostellar disks, out of which individual stars and their planets form. By a mechanism not fully understood, but believed to be associated with the strong magnetic fields associated with a young star, most of the angular momentum is transferred into the remnant accretion disk. Planets form from material in this disk, through accretion of smaller particles.
In our solar system, the giant gas planets (Jupiter, Saturn, Uranus, and Neptune) spin more rapidly on their axes than the inner planets do and possess most of the system's angular momentum. The sun itself rotates slowly, only once a month. The planets all revolve around the sun in the same direction and in virtually the same plane. In addition, they all rotate in the same general direction, with the exceptions of Venus and Uranus. These differences are believed to stem from collisions that occurred late in the planets' formation. (A similar collision is believed to have led to the formation of our moon.)