Answer:
As you may know, each element has a "fixed" number of protons and electrons.
These electrons live in elliptical orbits around the nucleus, called valence levels or energy levels.
We know that as further away are the orbits from the nucleus, the more energy has the electrons in it. (And those energies are fixed)
Now, when an electron jumps from a level to another, there is also a jump in energy, and that jump depends only on the levels, then the jump in energy is fixed.
Particularly, when an electron jumps from a more energetic level to a less energetic one, that change in energy must be compensated in some way, and that way is by radiating a photon whose energy is exactly the same as the energy of the jump.
And the energy of a photon is related to the wavelength of the photon, then we can conclude that for a given element, the possible jumps of energy levels are known, meaning that the possible "jumps in energy" are known, which means that the wavelengths of the radiated photons also are known. Then by looking at the colors of the bands (whose depend on the wavelength of the radiated photons) we can know almost exactly what elements are radiating them.