On a clear, dark night, our eyes can see about 6,000 or so stars in the sky. They seem to twinkle, or change their brightness, all the time. The scientific name for this twinkling of stars is stellar scintillation or astronomical scintillation. Stars seem to twinkle when we see them from the Earth's surface, because we are viewing them through thick layers of turbulent (moving) air in the Earth’s atmosphere.
The Earth's atmosphere comprises of layers of gases surrounding the Earth. It’s composed of 78% nitrogen, 21% oxygen, 0.9% argon, 0.03% carbon dioxide, and other gases. These gaseous layers insulate the Earth from extreme temperatures and block the Earth from much of the Sun’s incoming ultraviolet radiation.
As light of a star travels through these layers of the Earth's atmosphere, it is bent or refracted many times and in random directions (it happens whenever it hits a change in density - like a pocket of cold air or hot air). This random refraction results in the star appear to our eyes as twinkling.
Stars would not appear to twinkle if viewed from outer space or from a planet that doesn't have an atmosphere.