When sunlight is passed through a prism, it is dispersed into the colors of the rainbow. In fact, when you see a rainbow after a rain storm, it too is made by sunlight passing through many tiny prisms - the raindrops.
Careful study of these rainbows reveals that there are gaps between some of the colors. These gaps are called absorption lines, and depending on where they are in the spectrum (that is, where they are in the rainbow), scientists can tell what the light source is made of. Scientists also discovered that the temperature of a star is determined by its composition. So by observing the spectrum, scientists can tell the temperature of a star.