The The Bohr Model and Energy Levels says each kind of atom has its own ladder of energy levels, so it emits and absorbs its own set of photon energies. That is how astronomers know what the stars are made of, without ever touching one.
Key idea
Kirchhoff's three rules: a hot, dense object (a solid, or a dense gas like a star's interior) gives a continuous spectrum. A hot, thin gas gives an emission spectrum of bright lines. A cooler, thin gas in front of a hotter continuous source gives an absorption spectrum: dark lines at the same wavelengths that gas would emit.
Why it works
Why the same lines? Both come from the same jumps. A photon is absorbed only if its energy matches a jump up, and an atom emits only the energies of jumps down, and the jumps up and down are between the same pairs of levels. Why are absorption lines dark? The atoms that absorb a photon soon re-emit one, but in a random direction, so very little of that light continues toward you.
Common mistake
Thinking a gas absorbs different colors from the ones it emits. The dark lines line up exactly with the bright lines of the same gas. (Which lines show up depends on which levels the atoms sit in: cool hydrogen, nearly all in $n = 1$, absorbs only its ultraviolet lines; in a hot star's atmosphere many atoms sit in $n = 2$, so the visible lines appear dark.) Check: every absorption line must match an emission line of that element.
Worked example: Which spectrum?
You look at three things through a spectroscope: a glowing stove element, a neon sign, and sunlight. Which kind of spectrum does each give?
- Stove element: a hot solid, so a continuous spectrum.
- Neon sign: a hot, thin gas, so bright emission lines.
- Sunlight: the hot, dense Sun seen through its cooler outer layers, so a continuous spectrum crossed by dark absorption lines.
Answer: Continuous, emission, absorption
Worked example: Counting lines
A gas has energy levels at $-10.0$, $-6.0$ and $-4.0\ \text{eV}$. List the photon energies it can emit. If all its atoms start in the lowest level, which can it absorb?
- Emission (any jump down): $-6.0 \to -10.0$ gives $4.0\ \text{eV}$; $-4.0 \to -10.0$ gives $6.0\ \text{eV}$; $-4.0 \to -6.0$ gives $2.0\ \text{eV}$.
- Absorption from the lowest level: only jumps that start at $-10.0\ \text{eV}$: $4.0$ and $6.0\ \text{eV}$.
- The $2.0\ \text{eV}$ line would need atoms already in the middle level.
Answer: Emits $2.0$, $4.0$ and $6.0\ \text{eV}$; absorbs $4.0$ and $6.0\ \text{eV}$
In 1868 astronomers found a bright yellow line in the Sun's spectrum that matched no known element. The new element was named helium, from the Greek word for the Sun, and it was found on Earth 27 years later.