Sunlight (and starlight) is not a single color, but rather a wide range of different colors (wavelengths). This is because the light from the sun and stars is generated by their internal heat, and so the light they give off has a distribution of colors. This is similar to the light produced by an incandescent light bulb. We can look at this range of colors by passing their light through a diffraction grating, which produces a rainbow-like spread of colors, as you can see in the image below.
Another way to produce light is by exciting a gas of atoms, but this method only produces specific colors depending on what type of atom or molecule you stimulate. This is similar to the light produced by a compact florescent light bulb.
The pattern of colors emitted by excited atoms and molecules is called an emission spectrum. The emission spectrum of each atom or molecule is unique, like a human fingerprint, so you can identify the source of the spectrum just by looking at the pattern.
It turns out you can also do the opposite as well. If you put a gas or plasma in front of an incandescent light source, the gas or plasma will absorb exactly the same colors it would emit. This creates an absorption spectrum against the background light. A shadow on the rainbow, if you will, by which we can identify what the gas or plasma is made of.
The image below shows the absorption lines of the sun. The part of the solar atmosphere that produces the light we see is called the photosphere. The solar atmosphere above that is cooler than the photosphere, so it creates an absorption spectra. This is useful because we can use it to identify what atoms or molecules are in the upper atmosphere of the sun, and of course that helps tell us what the sun is made of.
The really cool thing is that we can also see absorption lines in starlight, which tells us which atoms and molecules the star contains. Doing a bit of chemistry from light years away, just by looking at shadows on a rainbow.