Dispersion is the optical phenomenon that explains why white light separates into its constituent colours when it passes through a transparent medium.
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 to 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 light rays are deviated as they pass from one transparent medium to another. The greater the difference between the refractive indices of the two transparent mediums, 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 deviated more than red, even though both rays came from the same white light that was initially travelling through the air.
The difference in deviation is explained by the fact that blue light has a higher index of refraction than the red light in the prism. The greater the index, the greater the deviation. It has been established that the index of refraction of the blue ray is 1.528 and that of the red ray is 1.511. This difference influences the angle of refraction of each of the two colours.
In a rainbow, the water droplets suspended in the air act like prisms and separate the colours.