Even though all colours of the visible spectrum travel with the same speed in vacuum, the speed of the colours of the visible spectrum varies when they pass through a transparent medium like glass and water. That is, the refractive index of glass is different for different colours.

When a polychromatic light (multi coloured or light containing more than one wavelength) like white light is incident on the first surface of the prism it gets refracted. But each constituent of the white light gets refracted through a different angle, i.e., white light gets dispersed. When these colours are incident on the second surface of the prism they again undergo refraction (they get refracted from a denser to rarer medium) and the colours are separated further. Thus a beam of white light incident on a prism splits into its constituent colours to form a spectrum.
Each constituent of the white light is deviated towards the base of the prism. Violet colour suffers the maximum deviation and red the least. The spectrum obtained is impure as the colours in the spectrum do not have any sharp boundaries i.e., each colour merge gradually into the next.
Recomposition of White Light
In order to get white light from the dispersed light the prisms are arranged as shown in the diagram. Recombination of the seven colours of the dispersed white light to get white light is known as recomposition of white light.