A star’s color is entirely governed by its temperature at the surface. Very similar to our idea of “red hot” and “white hot” giving an idea of the temperature of heated metal, the color of the star gives an idea of the temperature of the star.
The relationship between temperature and color is given by the black-body relation, which applies to any object which gives off light and doesn’t absorb light (like stars and heated metal). So objects like these which glow due to heat change colors as they heat up. The hotter an object is, the shorter the wavelength of the majority of the light it gives off, so as you heat an object, it will transition through the rainbow of colors from red to blue. However, iron really only goes from red to white, whereas stars can have colors anywhere from the extremely hot blue to the cooler deep red stars.
So the real question is, why are stars different temperatures?
Stars are a delicate balance between gravity crushing a star inwards, and the pressure from the radiation the star generates in its core. The more massive a star is, the more gravitational pressure can be exerted, so the more energy needs to be generated in the centre of the star. Fortunately, the extra gravity of the star can produce extra dense and hot regions near the centre, which allows the nuclear reaction in the centre to kick into high gear. This then produces the extra energy the star needs to balance out its extra weight.
So the heavier the star is, the more energy the star can produce at its core, which in turn means the star burns hotter and faster, and the hotter the star, the bluer it gets. By contrast, the lighter a star is, the less energy is formed at the core, so the surface of the star stays quite cool (relatively speaking) and red.
Sign up for the mailing list for updates & news straight to your inbox!