A prism (or an array) is used to break a beam of light according to its different frequencies.
The spectrum obtained can be continuous or discrete ("line spectrum").
One of the great discoveries of quantum mechanics is that the energy of an atom can only have certain well-defined values. It is "quantized" (see animation line spectrum of the hydrogen atom). For this reason, a gas composed of a single atom can absorb or emit a limited number of frequencies.
For a given element, the emission spectrum (upper part of the animation) has the same frequency as its absorption spectrum (bottom part).
source for the values of spectral lines: CDS Strasbourg University (link) from Reader J., and Corliss Ch.H. CRC Handbook of Chemistry and Physics; NSRDS-NBS 68 (1980).
Click on an element to select it. Draw a rectangle in the screen to zoom in.