When a strontium compound is heated in a flame, red light is produced. When a barium compound is heated in a flame, yellow-green light is produced. Why does this happen?
The color of the flame is due to the light emitted by certain salts. The atoms of element contained in the salt are excited to higher energy levels due to heat of the flame. Thereafter, the excited atoms return to the ground state emitting electromagnetic radiation of characteristic frequency. This radiation is seen by the viewer as emitted color.
For example, Sodium
Strontium salts and lithium salts produce:
Picture above shows emission spectrum of a metal halide lamp