Light is composed of seven colors of different wavelengths and frequencies.
Violet, Indigo, Blue, Green, Yellow, Orange, Red.
Violet – highest frequency (lowest wavelength) and Red – lowest frequency (highest wavelength)
Light changes its direction(or bends) when it travels from one medium to another (refraction). The different colors of different wavelength bend at different angles forming a band of colors (spectrum). The separation of visible light into various colors is known as dispersion.
Colours with lower frequency (which indicates lower speed) get diverted less as their refractive index is less. Hence we see red colour at the top of the rainbow.
A CD is made up of thousands of pits arranged in the form of spiral tracks. When visible light is incident on the pits, each pit diffracts light in all directions. Here CD acts as a diffraction grating(diffraction – change in direction and intensities of waves after passing through a narrow slits or edges). We know that diffraction gratings are dispersive i.e. they separate a polychromatic light into its constituents. Thus rainbow colours are formed. The colours which overlap (peaks of waves overlap) are seen brighter than the colours which cancel each other (peak of one wave overlaps with the trough of the other).
The distance between eye of the observer and each pit varies. The angle at which the observer sees the CD controls the colors seen.