The reason the chemical elements can do this is because of the number and places of electrons orbiting around the center of each atom of each chemical element. These electrons, when light hits them, absorb a specific wavelength, or color of light, and what color they absorb depend on their position around the atom. Since each chemical element has a certain number of electrons, each chemical element has this unique set of spectral lines.