When atoms absorb energy, through heating, from electricity, or by absorbing electromagnetic radiation, the electrons at a particular level can be pushed up to higher levels (at bigger distances from the nucleus). In time, they jump back down to a lower level radiating energy in the form of electromagnetic waves.
The frequency of the radiation depends on the size of the jump that the electron makes. Sodium has energy levels that cause the electrons to emit yellow light as they drop from one to the other. The energy levels in mercury are further apart and electrons emit ultraviolet radiation when they jump back down.
In the diagram, the colours of the 'down arrows' represent the colour of the light emitted as the electron makes that drop.