Perhaps this is something that you had no idea was even true!
I mean...I wouldn't blame you...
Usually, we associate heat with the colours red or yellow, and the sun seems pretty yellow from here on Earth, so why would hot stars glow blue?
By the way, when I say "hot", I mean really hot. The surface of the sun is about 6000 Kelvin (5500 degrees Celsius) and the stars that glow blue have surface temperatures of well over 10,000 Kelvin (9700 degrees Celsius)!
Firstly, let's start by clarifying that stars emit a variety of different wavelengths of light.
It's not like the sun only emits yellow light, and blue stars only emit blue.
The reality is that they emit a spectrum of different colours in varying intensities, and even emit wavelengths corresponding to radiation that our eyes aren't sensitive too, such as infrared, UV and so fourth.
I've explained what colours actually are, and why one colour would be produced instead of another in this article, so I'd be in danger of repeating a lot of that information if I were to go into the same details here. Therefore, I'd highly recommend checking out that article before continuing on with this one, but it's not necessary.
Suffice to say that the hotter stars will emit photons of higher energy, and a higher energy corresponds to a higher frequency, and hence a shorter wavelength.
Frequency is inversely proportional to wavelength.
Here's an illustration of the electromagnetic spectrum, where you can see that purple light is the shortest wavelength of visible light, and red is the longest.
Image credit: NASA
Therefore, we can say that blue light is more energetic than red light.
A direct result from the equation e = hf, where:
e = energy
h = Planck's constant
f = frequency
It's exactly because of this relationship between energy and frequency that really hot stars emit larger proportions of their light in the blue/purple spectrum, as the electrons that make up the atoms of gases responsible for emitting such light have a higher amount of energy that they want to get rid of in the form of photons of radiation, hence they emit higher frequencies of electromagnetic radiation (light), such as blue, purple and UV.
Cooler stars, on the other hand, like the the sun for example, are made of gases of which the electrons have less energy that they want to get rid of, and hence the light emitted from them have smaller frequencies such as red and yellow.
Importantly though, all stars will emit light across the spectrum, but there'll be particular wavelengths of light that are more intense than others, in that they're released more often.
Hopefully that's at least fairly understandable, although as I mentioned earlier, an understanding of where light comes from in the first place would definitely help solidify an understanding here, so I'd recommend checking out that article.
Before we finish up though, I just want to draw upon something that I also mentioned earlier, which is that the sun looks yellowish from Earth.
In reality, the sun is actually white, but it appears slightly yellowish from Earth because we're receiving the light after it's traveled through 50km or so of atmosphere.
Water, dust and gases in our atmosphere interact with this light, in that they scatter blue light more so than any other other light, which is why the sky appears blue at daytime.
Again, I have an article that explains how and why light gets scattered through the atmosphere (which is ultimately why the sky appears blue), so definitely check out that one here if you're interested.
It's probably one of my most comprehensive, detailed articles so I'd definitely say it's worth a read for anyone really, but especially people interested in physics!
Briefly though, with blue light being separated, this gives the impression to our brains that what we're seeing is mostly emitting yellow and red light, which is why it appears that way in the sky.
However, the sun is white in reality as it emits a roughly equal share of different colours which combine to form white.
Just a fairly quick one, but hopefully interesting nevertheless!
Thanks for reading!