In the early 1900's it was discovered that if you ran electricity through a gaseous element, like neon, it would produce light. No matter how much electricity was used each element only produced one color. We use this technology today in "neon" signs. The different colors are actually different elements.
It was later determined that the light produced by each element was a distinct mix of different wavelengths.
When electricity is run through the gas the electrons absorb that energy and are pushed from their original energy level into a higher energy orbital. It is said that the electron moves from the ground state into an excited state. An electron in an excited state is very unstable and must release the energy it's gained to return to its ground state. The energy is released as light.
The color of the light is dependent on how much energy is released. If the electron released a lot of energy the light would have a high frequency and short wavelength, probably being in the violet or blue color range. If the electron only released a small amount of energy the light would have a low frequency and long wavelength, like red light.
Atoms have many electrons and each electron can make several different jumps depending on how much energy it received. But there are a fixed number of transitions the electrons in a given element can make.
As a result each element can only absorb certain amounts of energy and emit certain types of light. This acts as a finger print for each element called an emission or absorption spectrum.
Scientists use these spectrum to analyze light from distant stars and determine what elements are inside.