Even though all colors of the visible spectrum travel with the same speed in vacuum, the speed of the colors 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 colors.
Dispersion of White Light
When a polychromatic light (multi-colored light - containing more than one wavelength) like white light is incident on the first surface of the prism, then each constituent of the white color gets refracted through a different angle, i.e., white light gets dispersed. When these colors are incident on the second surface of the prism they again undergo refraction (they get refracted from a denser medium to rarer medium) and the colors are separated further. Thus a beam of white light incident on a prism splits into its constituent colors to form a spectrum.
Each constituent of the white light is deviated towards the base of the prism. Violet color suffers the maximum deviation and red the least. The spectrum obtained is impure as the colors in the spectrum do not have any sharp boundaries i.e., each color merges gradually into the next.