An exploding firework is essentially a number of chemical reactions happening simultaneously or in rapid sequence. When you add some heat, you provide enough activation energy (the energy that kick-starts a chemical reaction) to make solid chemical compounds packed inside the firework combust (burn) with oxygen in the air and convert themselves into other chemicals, releasing smoke and exhaust gases such as carbon dioxide, carbon monoxide, and nitrogen in the process.
Check out our Fireworks Infographic.