Dispersion is the optical phenomenon that explains why white light is separated into its constituent colours when it passes through a transparent environment.
Isaac Newton was the first to demonstrate the decomposition of light. He demonstrated that white light could be broken down into a spectrum of colours when it passed through a prism, but that it could be recomposed when it passed through a second prism.
The diagram below illustrates the phenomenon of dispersion. White light enters the prism on the left of the image. Inside the prism, the polychromatic light (made up of several rays) is separated into seven monochromatic rays (made up of a single ray): red, orange, yellow, green, blue, indigo and violet.
Refraction is the phenomenon whereby rays of light are deflected as they pass from one transparent environment to another. The greater the difference between the refractive indices of the two transparent environments, the greater the angle at which the light is deflected.
However, each monochromatic ray (or each colour) has a different frequency, which means that each ray has its own refractive index in a given environment. As can be seen in the illustration above, blue is deflected more than red, even though both rays came from the same white light that was initially travelling through the air.
The difference in deflection is explained by the fact that blue light has a higher refractive index than red light in the prism. The higher the subscript, the greater the deflection. It has been established that the refractive index of the blue ray is 1.528 and that of the red ray is 1.511. This difference influences the angle of deflection of each of the two colours.
In a rainbow, it is the water droplets suspended in the air that act like prisms, separating the colours.