In 1801 William Wollaston observed a rainbow in close detail and noticed tiny dark lines in the visible spectrum. Here is an experimental setup for the prismatic observation of the solar spectrum by Wollaston:
In 1817 Fraunhofer took an even closer look at the Sun’s spectrum (IR, UV and visible) by expanding the spectrum onto a large wall. As a result, he found thousands of slices that were missing.
These are known as absorption lines or ‘Fraunhofer lines’. But why do they occur?
A major advance was made in 1859 by Gustav Kirchhoff and Robert Bunsen that explained why the dark lines occur. When certain chemicals were heated in Bunsen's burner, characteristic bright lines appeared.
In some cases these were at exactly the same points in the spectrum as Fraunhofer's dark lines. For example, these are the spectrum lines visible when we heat hydrogen gas. This is known as the Balmer series :
Light passing through cooler atmospheric hydrogen will show absorption lines in the exact same position. For example imagine sunlight passing through a tube of hydrogen gas and then split using a prism:
Emission lines refer to the fact that glowing hot gas emits lines of light, whereas absorption lines refer to the tendency of cool atmospheric gas to absorb the same lines of light. When light passes through gas in the atmosphere some of the light at particular wavelengths is scattered resulting in darker bands. These lines came to be known as ‘spectral lines’ and were cataloged by heating common elements until they produced light and measuring the wavelengths emitted.
Below is an interactive illustration. Click on different gasses to see how they absorb different wavelengths of light:
This provides a fingerprint that confirmed the presence of chemical elements at a distance. Astronomers use this fingerprint (which spans the entire spectrum) to determine the composition of distant stars (which are essentially balls of burning gas) as well as the atmosphere of stars and planets (that absorb light passing through their atmospheres).