Light coming from the stars undergoes refraction on entering the Earth's atmosphere. This refraction continues until it reaches the Earth's surface. This happens because of uneven heating of atmospheric air. Hence, the atmospheric air has to change refractive index at various altitudes. In this case, starlight continuously travels from a rarer medium to a denser medium. Hence, it continuously bends towards the normal.
The refractive index of air medium gradually increases with a decrease in altitude. The continuous bending of starlight towards the normal results in a slight rise of the apparent position of the star.
Since the physical conditions of the Earth's atmosphere keep changing, the apparent position of the star is not stationary. The star changes its position continuously, which makes it twinkle. This happens because starlight travels a very large distance before reaching the observer. However, the path varies continuously because of uneven atmospheric conditions. Hence, the stars seem to be fluctuating, sometimes appearing brighter and sometimes fainter. All this together gives rise to the twinkling effect of stars.