The amazing colors in exploding fireworks come from chemical reactions triggered by heat. Combustion propels fireworks into the air while oxidization provides the oxygen needed to excite the metal compounds in fireworks. Energy absorption and emission produce fireworks' unique color spectra.
Combustion occurs when the flame from a firework's fuse comes into contact with black powder, causing potassium nitrate, charcoal, and sulfur to combine. The combustion is highly exothermic (heat-producing). In most fireworks the heat and gas are forced out of the bottom of the firework shell, propelling the firework up into the sky.
Once a firework has reached its apex in the sky, the fuse reaches a compartment filled with an oxidizing agent and light-producing stars. Common oxidizing agents include nitrates, chlorates, and perchlorates. The oxidizing agents react with the heat and gas formed by combustion to produce enough oxygen for rapid combustion of the light- and sound-producing agents in the stars.
The oxygen produced by the oxidizing agents reacts with the elements in the stars to produce a hot, rapidly expanding gas. The atoms in this gas absorb the energy produced in the reaction, causing their electrons to move from their stable ground state to an excited energy state. When the electrons return to their ground state, they emit energy in the form of light. The color of the light depends on the type of element in the stars.