Why are different colors observed when compounds are subjected to flame?
The colors are determined by the amount of energy that excited metal electrons give off as they fall back to a lower energy level, giving off visible light.
The compounds are ionic compounds containing a metal cation and an anion. When subjected to a flame, the electrons of the metal become excited and move to a higher energy level, which is very unstable. Therefore, the electrons fall back to a lower level, giving off the same amount of energy that was absorbed. Some of this energy is in the form of visible light. Each metal has a specific color associated with it.