Question: how do diffraction gratings work?
Answer: A diffraction grating is an optical element, which separates (disperses) polychromatic light into its constituent wavelengths (colors). The polychromatic light incident on the grating is dispersed so that each wavelength is reflected from the grating at a slightly different angle.