When elements are heated, it causes their electrons to become excited. Electrons exist in discrete energy levels, and these energy levels are unique to each element. When the electrons are excited by heat, they are able to move up to a higher energy level through absorption of a specific amount of energy. However, the electrons are unstable in higher energy levels and so they drop back down to a lower level, or 'ground' state. When they do this, the electrons emit a photon, which has the same energy as the size of the energy gap between the level it is dropping from and the level it drops to. This energy emitted corresponds to a specific frequency of light (stated by the equation E=hf). Smaller frequencies correspond to radiation in the visible light region of the electromagnetic spectrum, which explains why we are able to observe a colour or colours when elements are heated.