Stars appear to twinkle due to the Earth’s atmosphere. When starlight passes through the atmosphere, it encounters varying air densities, temperature differences, and turbulent air currents. These factors cause the light to bend or refract in different ways, which leads to the apparent flickering or twinkling of the stars.
The effect is called stellar scintillation. The atmosphere acts like a giant lens that distorts the light, making the star seem to change in brightness and color, especially when seen from the ground. The closer to the horizon the star is, the more atmosphere the light has to pass through, which usually makes the twinkling more pronounced.
Stars seem to twinkle more than planets because planets are closer to Earth and appear as tiny disks rather than point sources of light. This allows the light from planets to average out the atmospheric disturbances, making them appear steadier than stars.