Spectral lines are the result of interactions between a quantum system (usually atoms, but sometimes molecules or nuclei) and individual photons. All spectra and spectral lines result from transitions between discrete energy states of matter in which photons of corresponding energy (and hence characteristic frequency or wavelength) are absorbed or emitted. The energy levels thus determined can be used to study atoms and molecules. A photon is absorbed when it has the correct energy to allow a change in the energy state of the system (in the case of an atom, this is usually an orbital jump of an electron); it is then re-emitted spontaneously, or at the same frequency as the original, or in a cascade, where the sum of the energies of the emitted photons is the same as that of the absorbed photon. The direction of the new photons will not be related to the direction of the original photon.
Depending on the geometry of the gas, the source of the photon, and the observer, either an emission line or an absorption line will be produced: if the gas is between the source of the photon and the observer, a drop in light intensity will be observed in the frequency of the incident photon, since the re-emitted photons will be in different directions than the original. This is an absorption line. If the observer sees the gas but not the photon source, he will see only the re-emitted photons in a narrow frequency range. This is an emission line.
The absorption and emission lines are extremely atom specific and can be used to easily identify the chemical composition of any medium through which light can pass (usually gases). They also depend on the physical conditions of the gas and are therefore widely used to determine the chemical composition of stars and other celestial bodies that cannot be analyzed by other means, as well as their physical conditions.
Other mechanisms besides atom-photon interaction can produce spectral lines. Depending on the physical interaction (with molecules, single particles, etc.), the frequency of the photons involved varies widely, and the lines can be observed along the entire electromagnetic spectrum, from radio waves to gamma rays.
An absorption line is a dark line in a continuous spectrum corresponding to the absorption of light or other form of electromagnetic radiation at a well-defined wavelength; the pattern of such lines is characteristic of specific atoms or molecules in the path of the radiation. When a light source with a continuous spectrum is viewed through a cool gas, dark lines appear in the spectrum. The wavelengths of the lines are identical to the wavelengths of emission lines from the same gas when heated. Spectral lines are often used to identify atoms and molecules.
The pattern of absorption lines in a spectrum is diagnostic of the types of atoms and molecules present in, for example, the surface layers of a star or the atmosphere of a planet. Absorption lines can be seen in the spectra of the Sun and other stars. Most are Fraunhofer lines, but some are produced in the cool interstellar gas along the line of sight and give clues to the physics and chemistry of the interstellar medium. Absorption lines in quasars carry information about intergalactic space.