By placing atoms of a metal into a flame, electrons can be induced to absorb energy and jump to an excited energy state, a quantum jump.  They then return to their ground state by emitting a photon of light (the law of conservation of energy indicates that the photon emitted will contain the same amount of energy as that absorbed in the quantum jump).  The amount of energy in the photon determines its color; red for the lowest energy visible light, increasing energy through the rainbow of orange yellow green blue indigo, and finally violet for the highest energy visible light.  Photons outside the visible spectrum may also be emitted, but we cannot see them.