Here's why:
* Spectral lines: The light from a star contains specific wavelengths (colors) that are absorbed by the elements in its atmosphere. These absorption lines create a unique "fingerprint" called a spectrum.
* Temperature and Absorption: The strength and position of these absorption lines are directly related to the temperature of the star's surface. Hotter stars have different absorption patterns than cooler stars.
* Spectral Classification: Astronomers have organized these patterns into spectral classes (O, B, A, F, G, K, M) with O being the hottest and M being the coolest.
So, by analyzing the spectral lines in a star's light, astronomers can determine its surface temperature and classify it into a spectral type.