Atoms in chemicals can absorb and emit energy depending on the situation. The electrons of the atoms occupy discrete energy levels. The energy difference between these levels is what determines an atom's absorption and emission characteristics. If an atom is exposed to electromagnetic radiation of the exact right wavelength to match the energy difference between two electron orbitals, the atom will absorb this amount of energy to allow the electron to occupy the higher energy state. Eventually, the electron will drop back to its resting energy state and the atom will emit a photon of energy accordingly. These energy amounts will be the same for the same atom since they both correspond to the same energy transition. This is why the different elements give characteristic emission and absorption spectra that can be used to identify and differentiate them.