Every element absorbs and emits light at a unique set of wavelengths. Reading those wavelengths identifies what something is made of without touching it, which is how the composition of stars was determined and why a philosopher's claim that it could never be known is the most quoted wrong prediction in science.

Isaac Newton split sunlight into a spectrum in 1666. In 1814 Joseph von Fraunhofer, making high-quality glass, noticed that the solar spectrum was crossed by hundreds of dark lines at fixed positions.

Joseph von Fraunhofer, who mapped hundreds of dark lines in the solar spectrum from 1814 and used them as wavelength standards without knowing what caused them.
Joseph von Fraunhofer, who mapped hundreds of dark lines in the solar spectrum from 1814 and used them as wavelength standards without knowing what caused them.Credit: Unknown authorUnknown author (Public domain).

He mapped them carefully, labelled the strongest with letters still in use, and used them as wavelength standards. He did not know what they were.

Gustav Kirchhoff and Robert Bunsen worked it out in 1859. Heating an element produces bright emission lines at characteristic wavelengths; passing light through a cooler gas of the same element produces dark absorption lines at exactly those wavelengths. The pattern is a fingerprint, and the dark lines in sunlight are elements in the Sun's cooler outer layers absorbing light from below.

An emission spectrum. Each element produces a fixed pattern of lines, which identifies it regardless of what else is present.
An emission spectrum. Each element produces a fixed pattern of lines, which identifies it regardless of what else is present.Credit: Philips Lighting (CC BY-SA 2.5 nl).

The explanation had to wait for quantum mechanics.

Electrons in an atom occupy discrete energy levels. An electron can move between levels only by absorbing or emitting a photon whose energy exactly matches the difference. Since the level structure is set by the number of protons and the arrangement of electrons, every element has its own set of gaps and therefore its own set of wavelengths.

This is why the lines are sharp rather than smeared, and why the pattern cannot be faked by a mixture: no combination of other elements reproduces another element's exact set.

Light from a mercury vapour lamp dispersed into its component wavelengths. The discrete lines rather than a continuous band are the signature of quantised energy levels.
Light from a mercury vapour lamp dispersed into its component wavelengths. The discrete lines rather than a continuous band are the signature of quantised energy levels.Credit: D-Kuru (CC BY-SA 3.0 at).

Auguste Comte wrote in 1835 that the chemical composition of the stars was something humanity would never know. He chose it deliberately as an example of a question forever beyond reach.

Kirchhoff and Bunsen answered it within twenty five years, and the answer arrived by a route Comte had no way to anticipate: not by going there, but by reading the light that arrives anyway.

Helium was found in the Sun before it was found on Earth. In 1868 an unexplained yellow line appeared in solar eclipse spectra, was attributed to an unknown element, and was named for the Sun. It was isolated terrestrially in 1895.

Spectroscopy is less a technique than a family of them, distinguished by which part of the spectrum is used and what it interacts with.

Atomic absorption and emission identify elements and measure their quantities, in metallurgy, environmental monitoring and forensics.

Infrared spectroscopy detects molecular vibrations, and since particular bonds vibrate at particular frequencies it identifies functional groups, making it the standard tool for identifying an unknown organic compound.

Nuclear magnetic resonance reads the environment of individual atomic nuclei and determines molecular structure in solution, and its imaging version is discussed separately.

Mass spectrometry is not strictly spectroscopy, since it separates by mass rather than by light, and is used alongside the others constantly.

In astronomy the applications compound. Composition from line identity. Temperature from line strengths and the shape of the continuum. Radial velocity from Doppler shift, which is how most exoplanets were first found. Rotation from line broadening. Magnetic fields from line splitting. Redshift, and therefore distance and the expansion of the universe, from displacement of the whole pattern.

The information travels with the light and requires no contact, no sample, and no cooperation from the source. A star ten billion light years away sends the same fingerprints as a flame in a laboratory, and the fingerprints have not changed in that time, which is itself a strong constraint on whether physical constants vary.

That is the deeper reason the technique matters. It works because the same physics operates everywhere, and every successful measurement is a further test of that assumption.