When an element has contact with flame, heat excites the electrons in the atom. This allows the electron to go from their ground states to a higher energy level. In this state, the electrons are unstable, so they needed to emit energy to return to their ground state. In this case, we could see a color that corresponds to the wavelength of light emitted by the energy in the form of electromagnetic radiation.
Above is an explanation of why we see different colors when elements or chemical compounds are put with flame. To see this concept with our bare eyes, we did the flame test lab as part of our chemistry class.
Six different compounds of salt were used in this experiment. Each of them was placed on the flame from a burner. Those different salt compounds emitted different colors, such as yellow, orange, mint green, red and magenta. Then, the wavelengths of the color were identified.
Nonetheless, this experiment was not conducted perfectly. One possible source of error can be from the way the color was observed. Color is something that is subjective. This would lead to inaccuracy in the wavelengths of chemicals identified. To avoid this error, a colorimeter can be used to accurately measure the wavelength.