Different chemicals emit different colors of light because their atoms have unique electron configurations, resulting in specific energy level differences. When atoms are heated or energized, electrons absorb energy and jump to higher energy levels (excited states). As these electrons return to their original (ground) states, they release energy in the form of light. The wavelength (and thus color) of this light corresponds to the energy difference between the excited and ground states, which varies between different elements and compounds. This unique energy difference creates a distinct color signature for each chemical.
In essence, the color of light emitted depends on the quantized energy jumps electrons make, which are unique to each chemical due to their distinct electronic structures. This phenomenon explains why elements produce characteristic flame colors or light emissions when energized.