When the white light rays of the sun fall on the rain drops they act as a tiny prism and reflect the light. Then the light splits into the seven colours: red, orange ,yellow ,green ,blue indigo and violet. This is also called the dispersion of light, first defined by Sir Isaac Newton.
Hope this helps.....
: )

This Is a Certified Answer

Certified answers contain reliable, trustworthy information vouched for by a hand-picked team of experts. Brainly has millions of high quality answers, all of them carefully moderated by our most trusted community members, but certified answers are the finest of the finest.
After a rain in the fore noon or after noon when the sun rays are making an angle of 40 to 42 degrees with the horizontal then we have a possibility of  primary rainbow. There are millions of rain drops suspended in air after a rain above earth’s surface.

See diagram.  

First the Sun rays are refracted in to water drops suspended in air some hundreds of meters in to the sky.  Then those light rays are totally internally reflected and then refracted to reach the human eye at a cone angle of 40 to 42 degrees.  The refraction of white light at the exit from rain drop results in a dispersion.

 Red color is visible on top and violet is on the bottom. The dispersion of light takes place at the last refracting surface of water drops. This is visible to us as the VIBGYOR color bands in a semicircular arc in the sky. Actually the rainbow is a full circle within the cones angles of 40 to 42 degrees.

A secondary rain bow is also formed with violet on top and red below other colors.
It is fainter than the primary rain bow. It is due to two total internal reflections before the light emerges out of the water drops with refraction. The refraction gives rise to dispersion of white light.