In another important experiment used to determine the nature…

In another important experiment used to determine the nature of atoms, a gas like hydrogen, neon or mercury is excited by sparking it with electricity. The light emitted is separated out into individual colors using a prism or diffraction grating and a few lines of colored light are seen. How do atoms produce these lines of light?