Stars twinkle when there appear to be variations in their brightness. Astronomers call this phenomenon atmospheric scintillation, and it’s caused by motion in the atmosphere.
Specifically, changes in atmospheric temperature cause small fluctuations in the air’s density. As starlight passes through the atmosphere, it’s refracted or slightly alters direction, creating a twinkling effect.
This is more obvious when viewing stars closer to the horizon because there’s a thicker layer of atmosphere. Astronomers compensate for atmospheric scintillation by using special adaptive optics on the most sophisticated telescopes. Space-based observatories like the Hubble also allow us to view stars and other objects without atmospheric scintillation.