The explosion of the firework produces gases, and their electrons are excited. As they return to their ground state, they emit colored light according to the chemicals used: blues from copper compounds, yellow from sulfur, green from barium, and so on.