Fireworks are pyrotechnic explosives that contain colour-producing chemicals. The colour-producing chemicals are basically metal compounds. That is because different metals emit different coloured light when they are heated.
For example here are some common metal compounds and the colour they emit:
- SrCO3 (strontium carbonate) – Red
- CaCl2 (calcium chloride) – Orange
- CuCl2 (copper chloride – Blue
- KNO3 (potassium nitrate) – Purple
- Titanium, aluminium, or magnesium powders – White
- For more colours go here.
To see which colour a metal emits you can use a flame test. A flame test is a procedure used to detect the presence of certain metals, based on the flame colour that the metal produces. It looks cool, see: