Emission lines of ionized from hot gas of different elements have distinct and unique wavelengths and patterns.
Emission lines from a laboratory reference lamp (Hydrogen, bottom) is compared to the spectrum of an astronomical source to identify lines.
An example of a spectrum from a star from the near-infrared to the near-ultraviolet. Discrete line features here are seen as absorption.