For a neutral hydrogen atom, spectral lines are formed when an electron transitions between energy levels.
The Lyman-alpha absorption lines in the quasar spectra result from intergalactic gas through which the galaxy or quasar's light has traveled.