The twinkling of stars is due to atmospheric refraction of star-light.
The atmosphere of the earth is made of different layers. It is affected by winds, varying temperatures, and different densities as well. When light from a distant source (a star) passes through our turbulent (moving air) atmosphere, it undergoes refraction many times. When we finally perceive this light from a star, it appears to be twinkling! This is because some light rays reach us directly, and some bends away from and toward us. It happens so fast that it gives a twinkling effect.