Each atom and molecule has its own light fingerprint that, like yours, is unique. But unlike yours, this fingerprint is made of light. Elements and compounds emit identifying sets of “colors,” or wavelengths, of light. (“Colors” is in quotes because the light is not always visible, extending to infrared and radio bands on one side and ultraviolet and gamma rays on the other.) No two color combinations are the same, allowing astronomers to accuse specific chemicals of being in stars, gas clouds, or planetary atmospheres.
Astronomy magazine subscribers can read the full answer for free. Just make sure you're registered with the website.