A page from the "Causes of Color" exhibit...
What causes the bright colors in fireworks?
Fireworks
Pyrotechnic displays demonstrate the bright colors produced by both incandescence and gas excitations. While the brilliant whites rely on the incandescence of metals such as magnesium, fireworks manufacturers use elements that react during the pyrotechnic explosion to emit colors by luminescence, through excitation of gas molecules.
Fireworks contain an explosive powder, along with a binding paste, mixed with the signature chemicals responsible for its bright colors. 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. Purple can be created by using strontium (red) together with the blues of copper.
For each substance, there are specific energy differences between the excited state and the ground state, determined by quantum probabilities. The wavelength, and so the color of the light emitted, is fixed by these energy differences, giving each substance a "fingerprint" line emission spectrum.