Stars twinkle because their light passes through constantly changing layers of Earth's atmosphere, each with slightly different density and refractive index. This repeated atmospheric refraction makes the star's apparent brightness and position fluctuate. Planets usually twinkle much less because their visible discs average out those fluctuations.