The story
A telescope gathers light from a star that nobody can visit. Spread that light into its colors, and a surprising pattern appears. Narrow dark lines interrupt the rainbow. Those missing colors are clues to the star's ingredients. Astronomers use spectroscopy, the study of light separated by wavelength, to read them. Wavelength means the distance between matching parts of a light wave, and different wavelengths appear as different colors.
Hot material deeper in the star produces a wide range of light. As that light passes through cooler gas above, atoms absorb certain wavelengths. Each element, a substance with one kind of atom, has a characteristic pattern. Compare the star's dark lines with laboratory measurements, and familiar elements appear. Hydrogen leaves recognizable lines whether it is studied on Earth or in a distant star's outer gas.
One line alone might not settle the answer. Several matching lines make the identification stronger. Temperature and other conditions affect how clearly lines appear, so a dark line's strength is not a simple ingredient label. Scientists compare patterns and use models to interpret them. The remarkable part is the shared physics: atoms far away interact with light according to the same rules that laboratory atoms follow here.