In 1860, physicist Gustav Kirchhoff laid out three rules describing every spectrum you'll ever encounter, based only on what's producing the light:
Notice: the emission lines and the absorption gaps sit at exactly the same positions — same element, same wavelengths, just bright-on-dark instead of dark-on-bright.
A continuous spectrum — every color present, no gaps — comes from a hot, dense source, like a glowing lightbulb filament. An emission spectrum — only a few bright lines on an otherwise dark background — comes from a hot, low-density gas. An absorption spectrum — a continuous rainbow with specific dark lines missing — appears when a continuous source is viewed through a cooler, thinner gas that's soaking up exactly those wavelengths.
An electron orbiting an atom's nucleus can only occupy specific, fixed energy levels — never anything in between. To jump up a level, an electron has to absorb a photon carrying exactly the right amount of energy; too little or too much simply won't do it. Since a photon's energy determines its wavelength, that means an atom can only absorb light of very specific wavelengths — the ones that exactly match a gap between two of its allowed energy levels.
Every element has its own particular arrangement of electron energy levels, which means every element produces its own particular pattern of spectral lines — no two elements share the same set. That pattern is as reliable an identifier as a fingerprint: find hydrogen's exact line pattern in a spectrum, and you've found hydrogen, whether that spectrum came from a lab flame or a star a thousand light-years away.
A lab sample produces bright emission lines at the same positions where a distant star shows dark absorption lines. What does that tell you?
A star's hot, dense interior produces a continuous spectrum on its own. But that light has to pass through the star's own cooler outer atmosphere before it reaches us — and that outer layer absorbs its own characteristic wavelengths along the way. That's why real stellar spectra are absorption spectra: a continuous rainbow with a forest of dark lines, each one a signature left by a specific element in the star's atmosphere.
Here's an unknown star's absorption pattern. Compare it to the four reference fingerprints below and pick the match.
In 1868, astronomers studying the Sun's spectrum during a solar eclipse found a bright yellow emission line that didn't match any known element on Earth. They concluded, correctly, that it must belong to a brand-new element — and named it helium, after helios, the Greek word for the Sun. It would be another 27 years before helium was finally isolated in a laboratory here on Earth.
One more thread worth knowing about, even briefly: spectral lines don't just reveal what an object is made of — their exact position can also shift slightly if the object is moving toward or away from us, an effect called the Doppler shift. That's a tool for a later lesson, but it starts from exactly the same fingerprint-matching skill you just practiced.