Stars twinkle due to the atmospheric refraction of starlight.
As the stars are very far away, they behave as almost a point source of light.
When the light coming from stars enters the earth's atmosphere, it gets refracted at different levels because of the variation in the air density.
The path of rays of light coming from the star goes on varying slightly, the apparent position of the star fluctuates and the amount of starlight entering the eye flickers.
So, sometimes, the star appears brighter and at some other time, fainter. Thus, the stars twinkle.