When light travels from one medium to another, it bends. In other words, it changes direction and moves at different speeds in different mediums. This property of light is called “refraction”.
We also know that white light is made up of different colours. Different colors of light have different frequencies. Except in vacuum and air, they travel at different speeds in different mediums.
If you were to allow a beam of light to pass through a simple prism, it will bend when it enters the prism, when it leaves the prism it bends again. The different colours of the white light travel with different speeds inside the prism. The slanted surfaces of the prism makes the different colours emerge separately, thus in addition to bending light as a whole, a prism separates white light into its component colors. This splitting of light into its component colours is called dispersion, where prism is a dispersing element.
This is exactly what happens when the sun rays hit droplets of water. When the sunlight strikes a raindrop, the light is refracted (bent) because the light is moving from one medium(air) to another( water). Drops of rainwater can disperse light in the same way as a prism.. When the light comes out of the water droplet, the sun's rays (white light)have now been split into their component wavelengths (colors). In this way, each individual raindrop behaves just like a prism, dispersing white sunlight into its seven component colors and a rainbow is formed.
The rainbow we see is thus a result of many, many raindrops bending the sun's rays.