They add chemicals to the explosive mixtures that emit specific colors of light when subjected to heat. You could throw some of these same chemicals into your fireplace if you thought that a green fire, for example, might be more romantic.
When you throw an atom into a fire, it can pick up some of the fire’s energy by making its electrons move faster. These “hot” electrons are just dying to return to their relatively sluggish, natural energy states (Techspeak: their ground states). The easiest way for them to do that, easy for an electron, that is, is to discharge their excess energy in the form of a blast of light. When enough atoms in a fire are simultaneously taking on heat energy and throwing it back off in the form of light, we can observe a very bright light.
Every type of atom or molecule has a unique set of electron energies to begin with. Therefore, each type of atom or molecule in the flame will be able to take on and throw off only its own unique amounts of energy. That is, different atoms and molecules will be emitting different wavelengths or colors of light.
Techspeak: every atom or molecule has its own, unique emission spectrum. Unfortunately for the fireworks manufacturers, most atoms and molecules emit their light in colors that humans can’t see: in the ultraviolet or infrared regions of the spectrum. But the atoms of some elements emit light in brilliant colors that we can see.
Here are some of the kinds of atoms (in the form of their chemical compounds) that are used to make the colors in fireworks:
Reds: strontium (used most often) makes a crimson light, calcium makes yellowish red, lithium makes carmine. Yellows: sodium makes a bright, pure yellow. Greens: barium (used most often) makes yellowish green, copper makes emerald green, tellurium makes grass-green, thallium makes bluegrass green, zinc makes whitish green. Blues: copper (used most often) makes azure, arsenic makes light blue, lead makes light blue, selenium makes light blue. Violets: cesium makes bluish purple, potassium makes reddish purple, and rubidium makes violet.
The next time you have a fire going in the fireplace or on the beach, sprinkle some crushed table salt or some powdered bicarbonate of soda on it and you’ll see the brilliant yellow flame color that sodium makes. If you have one of those salt substitutes around, the kind that’s sold for people on sodium-free diets, toss some of it onto the fire. It contains potassium chloride instead of sodium chloride, and you’ll see potassium’s characteristic reddish-purple flame color.
If you happen to be taking lithium for a manic depressive condition, your medicine will make the most beautiful red flames you’ve ever seen.