Light takes the path of least time. Since it can interact with matter as it passes through, the apparent speed of light changes, depending on the substance. The index of refraction of a substance is the ratio of the speed of light in a vacuum and the speed of light through that substance. In essence, it is a measure of the bending of light through the substance.
Since blue light has a shorter wavelength than red light, it bends more as it passes through a prism. This is why a prism is able to separate white light into its constituent colors. A spectroscope, or spectrometer, uses this phenomenon to spread out light, in order to study it in more detail. A diffraction grating acts like many tiny prisms to separate light out even farther.
When high voltage is applied across a tube of gas, the gas glows with characteristic colors. When the light is viewed through a spectroscope, the colors separate out into bands, as seen above. You can see that for these two gases, the spectral colors are different. The gas on the left is helium, and the gas on the right is nitrogen. Viewing a gas in this way allows us to determine what kind of gas it is. We can use spectroscopy to determine the kind of gas that made the light emitted by a star. These spectra are called emission spectra, because they are the colors of the emitted light.
When light from an emission spectrum passes through a cooler gas, the photons interact with the gas and scatter, leaving a gap for the constituent colors. The hydrogen spectrum is shown above, for the emission spectrum and for the absorption spectrum. The absorption spectra shows gaps where the photons were absorbed and re-emitted.
Kirchoff's laws summarize the possible kinds of spectra seen. Light coming directly from a radiating blackbody gives a continuous spectrum. This is because it typically emits all possible wavelengths of light. Light from a source that passes through a cloud of cool gas shows an absorption spectrum. Light emitted by a hot cloud of gas shows an emission spectrum.
Spectroscopy is the study of the light spectrum, or collection of wavelengths of light, that are produced when light interacts with matter. In these pages, we will focus on the emission and absorption spectra present in starlight.