Rainbows are produced when sunlight:
When sunlight incident on raindrops formation of a Rainbow occurs in the sky. These raindrops work as a prism. When sunlight hits a raindrop, some of the light is reflected. The electromagnetic spectrum is made of light with many different wavelengths, and each is reflected at a different angle. Thus, spectrum is separated, producing a rainbow.