The short answer is Earth’s air
Stars twinkle because of Earth’s atmosphere. Starlight passes through layers of air moving at different speeds and temperatures, and each layer bends the light a little. The result is that a star’s brightness seems to flicker, and sometimes its color does too. The star itself isn’t changing. The air between you and the star is.
Why stars near the horizon twinkle more
A star low in the sky shines through more air than one overhead, so there’s more turbulence to bend its light. That’s why stars near the horizon often twinkle more strongly. Stars overhead usually look steadier.
Why planets look steadier
Planets tend to look steadier than stars. A star is effectively a point of light, so the bending of the air can shift its brightness noticeably. A planet appears as a tiny disk, and the flicker from different parts of that disk tends to average out.
Twinkling and telescope views
Astronomers describe how steady the air is as seeing. When seeing is poor, stars shimmer and telescope images look soft and wobbly. The idea is covered in what is seeing and transparency in astronomy.
If the stars are twinkling hard, expect fine detail to look soft, even through a telescope. Lower magnification often gives steadier views on a shaky night, and you can check conditions in advance with how to read a clear sky chart.
Why stars sometimes flash color
Light bends slightly differently for each color, so a twinkling star can flash red, green, or blue for a moment. It’s the same effect as the twinkling itself, with the colors separating briefly. That’s why strongly twinkling stars can look like they’re changing color.