When atoms gain energy by heating, from electricity, or by absorbing electromagnetic radiation, some electrons jump to higher energy levels. Electromagnetic radiation is given out when the electrons drop back to lower levels.
The frequency of the radiation depends on the size of the energy jump. Atoms of elements such as neon and sodium give out light in the visible region of the spectrum. Other atoms, such as mercury atoms, give out light in the ultraviolet region.