Image: Omega Centauri globular cluster in 2009. Credit: NASA, ESA, and the Hubble SM4 ERO Team.
The color makes it possible to classify the stars according to their spectral type (which is related to the temperature of the star). The spectral types go from the most violet to the most red, that is to say from the hottest to the coldest, and are classified by the letters O B A F G K M . O and B stars are blue to the eye, A stars are white, F and G stars are yellow, K stars are orange, M stars are red.
Stars are of different colors because they have different temperatures and compositions. Stars are essentially large balls of gas that produce light and heat through the process of nuclear fusion in their cores. The color of a star is determined by its surface temperature, with hotter stars appearing more blue and cooler stars appearing more red.
Scientists use an instrument called a spectroscope to analyze the light from stars and break it down into its component colors. This allows them to determine the temperature of the star, which in turn determines its color. The hottest stars, with temperatures above 30,000 Kelvin, appear blue or blue-white, while cooler stars, with temperatures below 3,000 Kelvin, appear red or orange.
The composition of a star can also affect its color. Stars that have more hydrogen in their atmosphere appear bluer, while stars that have more heavy elements appear redder. This is because the heavier elements absorb more of the blue light and scatter more of the red light, giving the star a reddish tint.
In summary, the color of a star is determined by its surface temperature and composition. Hotter stars appear bluer, while cooler stars appear redder. The composition of the star's atmosphere can also affect its color.