Stars twinkle due to atmospheric refraction of starlight. The light from the star on entering earth’s atmosphere undergoes refraction continuously before it reaches the earth.
Refraction occurs and refractive index changes.
As 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.
Therefore sometimes star appears brighter and sometimes twinkle.