Flame test

The flame test is mainly caused by metallic elements contained in the material.
And, the same reaction occurs when it exists as a pure substance as well as when it is chemically bonded to another substance.

The principle of the flame test

The flame test occurs when electrons that are excited by receiving thermal energy return to their original orbit and emit light with a wavelength corresponding to the energy difference.
The energy orbits of electrons are quantized, and each orbit has different spacing, so each element has its unique color of the flame test.

The different colors of fireworks are the use of the pyrotechnic reaction of metallic elements.

Continuous spectrum

Incandescent bulbs emit light in all visible wavelengths by thermoelectrons. The spectrum’s continuous view is not only because a specific value of energy is emitted but because energy is evenly emitted over the entire visible range.
The continuous spectrum is well observed in a dense state because the atom’s electron orbits interfere with each other and cannot emit their own light. (E.g., solid or liquid, dense gas)

Line spectrum

When looking at the spectrum of light emitted from a fluorescent lamp, sodium lamp, neon sign, or flame test, only distinct wavelengths of light appear. The observed spectrum is called a line spectrum because it looks like a bar code.
Line spectra are well observed in sparse conditions because the atoms must emit their own light without interfering with each other. (E.g., gas or plasma state)