Each element, so to speak, has its own fingerprints, possessed by no other element. This fact is utilized in chemical analysis and in many other applied fields. The wave lengths absorbed are identical to the wave lengths that the gas would emit when properly excited. Photons of the proper wavelengths can be absorbed by the gas atoms and re-emitted in random directions. Because most of these particular photons do not reach the telescope, the spectrum is dark at the wavelengths of the missing photons.
Stellar spectra are dark line spectra.
Some of the dark lines are due to hydrogen, others to helium, still others to other elements. From a careful study of these lines, the chemicals present on a star, as well as other information, are obtained.