When electromagnetic waves, including light, pass through a transparent medium, they refract and continue to propagate in a different direction. The angle of refraction of light depends on the refractive index of the medium. The refractive index of the medium, in turn, depends on the frequency of the incident light. This dependency is called the phenomenon of Dispersion.
As a result of the dispersion phenomenon, red light refracts the least, while violet light refracts the most. You can observe the separation of light emitted by various ionized gases into its components (spectra) when passing through a triangular prism.
The spectrum of light emitted by the atoms of each substance when they return to their original state after excitation is considered the "signature" of that substance.