Two things are needed for a rainbow yo form, raindrops and the sun. The raindrops act like tiny prisms. As the sun's rays enter a raindrop, some of the light is reflected back. The rest of the light is refracted into the water.
The refracted light is spread into the spectrum of colors. As the different wavelengths of light reach the back of the raindrop some are refracted out of the raindrop. The rest of the light is reflected back into the water. Finally the light is refracted into the air. There are millions of these tiny prisms during a rain storm. Together they make a rainbow.