Some elements can change the color of a flame because of the excitation and relaxation of their outermost electrons. When the energy released during relaxation is great enough to produce visible light, the flame changes color accordingly. Different amounts of released energy result in different colors.
When electrons absorb energy, such as heat, they become excited and can change energy levels. The relaxation of an electron, when it falls from one energy level to a lower one, gives off energy, sometimes in the form of light. Because every element has unique atomic forces, the energy required for electrons to change energy levels and the energy subsequently released as electrons relax differs. These differences in energy produce the varying colors seen when burning certain elements in flames.
The flame test is a laboratory procedure in which different chemicals and elements are identified by burning them in a flame and identifying if the color produced is representative of a species or element. The flame test is useful, but can be unreliable for several reasons, such as the dependency on individuals to identify specific colors and the fact that certain elements can mask the presence of others by giving off a different color, resulting in a mixed sample.