The rainbow is produced due to:
Dispersion and total internal reflection of sunlight by water drops in the air
In a rainbow, the white light is split into its components. The raindrops behave somewhat like prisms, dispersing the white light into its component colours. These are then internally reflected if the sunlight hits the water drops at the proper angle and emerge from the other end.