Ordinary light seems white as it shines, but it is actually a combination of colors, violet, indigo, blue, green, yellow, orange, and red. Any time the light gets broken up, as in a soap bubble, an oil puddle, a piece of cut glass, or a diamond, we see all or most of these colors.
In the case of a rainbow, the light rays of the sun hit the raindrops in the air. These raindrops act as tiny prisms that break up those rays and send the various colors back to our eyes. This is why you can see a rainbow when the sun is out during or right after a shower.
And you have to be standing with the sun behind you and the raindrop-filled sky in front of you, for a rainbow forms in the sky opposite the sun.
The light of the moon can cause a rainbow too, a lunar rainbow, although its colors are weaker than those created by the sun!