The phenomenon of rainbow happens due to:
Dispersion of sunlight due to water drops
Rainbow happens due to the dispersion of sunlight. Dispersion of sunlight occurs when white light breaks into its component spectrum of colours as it passes through the water droplets.