The amazing colours in exploding fireworks come from chemical reactions triggered by heat. Combustion propels fireworks into the air while oxidisation provides the oxygen needed to excite the metal compounds in fireworks. Energy absorption and emission produce fireworks' unique colour spectra.
Combustion occurs when the flame from a firework's fuse comes into contact with black powder, causing potassium nitrate, charcoal, and sulphur 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 oxidising agent and light-producing stars. Common oxidising agents include nitrates, chlorates, and perchlorates. The oxidising 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 oxidising 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 colour of the light depends on the type of element in the stars.