I know why planets revolve around the sun. But why do they rotate on their axis?
Pretty much the same reason; the original particles that "fell together" to initially form the planet were not all heading directly for the center (in fact, is likely that virtually none of them were). So, rather than colliding perfectly head-on and coming to a stop, they all fell into decaying orbits around a common center of gravity. The number of particles orbiting in one direction was greater than the number orbiting the other direction, and this imported and inherent trait of angular momentum to the overall system.
Now, this next bit I'm not entirely certain about, but I imagine the rotation of the original accretion disk from which the planets formed contributed an influence rather like the Coriolis effect to determine which direction of rotation would dominate. That is just supposition on my part.
At any rate, because they flowed in a very low-friction environment, resulting planets just keep spending until something stops them.
I've wondered about this too. If you look down at the solar system from the north, the planets go around the sun in a CCW direction and most planets, such as Earth, rotate in a CCW direction from that view.
But, it seems that when the planets accreted, material inside the orbit is going faster and outside the orbit is going slower, so as the particles are collected, the planets should rotate CW instead (it helps to draw a picture).
Is that does seem a little perplexing at first. However, rather than making a picture, I think it might help more to imagine a video of a planet coalescing from the accretion disk. If you draw a line describing the eventual orbit of the finished planet (where the center of mass will be), you can see that particles moving toward that line from the center of the solar system are slowing down as they moved higher orbit, while particles falling into that line from further outside are speeding up as they falling to lower orbit. I think it is this that causes the planets' tendency to rotate in the same direction as they orbit.
Separate names with a comma.