It is to do with the electronic properties of the materials – that is the different electron energy levels that exist for different chemicals. If we were to excite electrons from low energy levels to high energy levels, the electrons will drop back down and release light. The colour of the light (ie its wavelength), is determined by the size of the energy gap which is characteristic of the chemical.
Comments