Rainbows are formed when sunlight falls on the water droplets which remain suspended in air for sometime after the rainfall.
It is caused by dispersion of sunlight by tiny water droplets, present in the atmosphere. A rainbow is always formed in a direction opposite to that of the Sun. The water droplets act like small prisms. They refract and disperse the incident sunlight, then reflect it internally, and finally, refract it again when it comes out of the raindrop. Due to the dispersion of light, different colours reach the observer’s eye.