When the light from an incandescent light bulb (you know, the kind you probably use in your lamps), is bent by a prism or grating, the result is a continuous spectrum like the one shown below.
However, light from a star passes through the gas in the star's atmosphere before it reaches us. This gas absorbs some of the wavelengths (or colors) of the light but not all wavelengths are absorbed. The wavelengths absorbed by the gas depends on the elements in the gas. As a result, the light that we see (the light that made it through the gas without being absorbed) is void of some of the colors. For example, we might see something like the spectrum shown below which is called an absorption spectrum.
Here's the really cool thing!Those dark absorption lines tell us the composition of the gas that makes up the star's atmosphere.
Not only can a gas absorb light, it can also give off light. If atoms in a gas are excited to high energy, perhaps by colliding with one another, then when those atoms lose energy, they give off light. Here's the really cool thing! They give off exactly the same colors of light that they absorb. The resulting spectrum is called an emission spectrum and is shown below. Notice that the bright lines in the emission spectrum correspond exactly to the dark lines in the absorption spectrum.
Each element emits and absorbs its own unique set of spectral lines (or colors).
That means that the colors (or wavelengths) absorbed by the atmosphere of the star tells us what elements it's composed of. All we have to do is look at the light to know what it's made of--no spacecraft necessary! The spectrum of an element is like a fingerprint that gives us a clue to the existence of that element in the star.
For example, the above absorption and emission spectra are unique to hydrogen (H). If you use a telescope, grating, and CCD camera to collect an absorption spectrum from a star and if you notice that those dark lines corresponding to red (656.2 nm), green (486.2 nm), violet (434.1 nm), and violet (410.2 nm) are present in the spectrum, then you know that H exists in the atmosphere of the star.
You should be able to identify from a picture of the spectrum whether it is a continuous spectrum, absorption spectrum, or emission spectrum. You should also know that the wavelengths of lines in the emission or absorption spectrum allows us to identify the elements (i.e. types of atoms) in the gas.
This simulation by Bruce Sherwood shows how emission and absorption spectra are produced.