Sunlight hitting a CD produces a rainbow due to diffraction, not refraction. The CD's spiral of tiny pits encodes digital information and creates closely-spaced lines on its metallic layer. These lines function as a diffraction grating, dispersing light into its component colors. This phenomenon can be further explored by searching for "CD diffraction." Understanding this optical effect highlights the interplay between light and the physical structure of the CD.