When a chemical burns or there’s a chemical reaction, electrons in the atoms get excited and jump up to higher energy levels, and release photons when they fall back into their original place. Different chemicals/ fuels release different frequencies of photons because they have different arrangements of electrons.
E: like others have pointed out, this explains the flame color, but not really the smoke color. Smoke no longer radiates light in the visible spectrum in the way I described above, so the color of the smoke is just the color of whatever byproduct the reaction produces.
Latest Answers