I'm not sure if you've come across this before, but energy can be thought of as discrete (set amount that can only take one value - like £1) packets of energy which we call Quanta.
A photon is an example of quanta (it is the quantum of the electromagnetic field), and when it collides with an atom it can cause an electron in the atom to jump up an energy level. It is now in an "excited state".
However, electrons prefer to be in their ground state - closest to the nucleus - so the electron then jumps back down. In doing this, it emits a photon with an amount of energy equal to the energy difference between the two energy levels.
The thing is, different elements have unique energy levels, and so the electrons in an atom of that element can only absorb certain quanta depending on if the discrete amount of energy in the quanta matches the discrete amount of energy between the lower and higher energy level.
This means that we have elements which will only absorb and emit certain quanta and therefore certain frequencies of radiation. When we pass light through a gas form of a certain element, the wavelengths of light that correspond to the right quantities of energy will be absorbed by the atoms. We see this as dark lines in the spectrum of light - absorption lines.
In hot gas, the atoms are already excited, and the electrons are in higher energy levels. Emission lines are caused by the electrons in these excited atoms jumping down a level and emitting the corresponding frequency of light.
Hope this helps - it's a fascinating subject so let me know if I can help with anything else:)