On an atomic scale, this happens because of the electrons in the atoms of the sample - an electron can absorb light to gain energy. From experiments, electrons only ever absorb certain amounts of energy, suggesting an electron's energy must fit onto set, quantised, discrete "energy levels". The process of an electron going to a higher energy level is called "excitation". For any atom of a particular element, the energy needed to excite an electron from one specific energy level to another will be the same. This is important because it allows us to compare the absorption lines of say, the atmosphere of a far away planet, to the absorption lines of elements we know to exist in a lab. We can then reach a conclusion about what the distant planet's atmosphere may be made of.