diffraction grating
Tilt a CD or DVD under a lamp and its surface flashes with rainbow colours, sweeping as you turn it. That shimmer is not paint; it comes from thousands of microscopic parallel grooves acting as a diffraction grating. A diffraction grating is a surface ruled with a great many equally spaced, closely packed slits or lines, and it is the sharpest tool we have for splitting light into its colours. It answers the question: how can we spread light into a spectrum far more precisely than a prism can?
A grating is really a double-slit experiment taken to the extreme, with thousands of slits instead of two. As with two slits, bright beams appear only where light from every slit arrives in step, when the path difference between neighbours is a whole number of wavelengths: d sin(theta) = m lambda, where d is the spacing between adjacent lines, m is the order, and lambda is the wavelength. Because thousands of slits must all agree, these bright maxima are extremely narrow and sharp, and crucially each wavelength appears at its own angle. Send in white light and the grating fans it into a clean spectrum; the more lines per millimetre, the wider and better-separated the colours.
Diffraction gratings are the heart of the spectrometer, the instrument scientists use to read the spectrum of a star, a flame, or a distant galaxy and so identify which chemical elements are present, each element emits its own signature set of wavelengths. Gratings are more precise than prisms and do not rely on dispersion in glass. An honest note: the same light appears at several angles, one for each order m, so a grating produces multiple spectra (first order, second order, and so on), which can overlap at high orders, something the user must plan around.
A grating with 500 lines per mm has line spacing d = 1/500 mm = 2000 nm. Green light (lambda = 550 nm) appears in first order (m = 1) at sin(theta) = lambda/d = 550/2000 = 0.275, so theta = 16 degrees, a wide, cleanly separated angle.
Sharp maxima at d sin(theta) = m lambda; each colour at its own angle.
A grating gives far sharper, better-separated spectral lines than a prism, because thousands of slits interfere. But it produces several orders at once, which can overlap and confuse the spectrum if not accounted for.