The separation of electromagnetic waves into their individual components based on their frequency or wavelength.