Firework displays will dazzle Americans from coast to coast this Thursday. But while you might have Thomas Jefferson to thank for the Declaration of Independence -- and by extension, the Fourth of July -- it’s chemistry that powers those colorful explosions in the sky.  

Fireworks display different colors due to the various kinds of materials packed inside them. When certain metals are heated to a certain temperature, electrons momentarily jump to a different energy level. When the electron settles back down to its original energy level, that cooling process emits a photon. Depending on the material, the photon will have a different wavelength and, hence, a different color.

For instance, while sodium appears gunmetal gray in person:

It creates bright yellow light when it burns:

You can see this effect in sodium lamps as well:

Barium, which when compounded with sulfur and oxygen is used in X-ray imaging of the digestive system, is also used in fireworks to produce a green color. Yellowish green colors come from the compound barium chloride; barium nitrate gives a brighter green.

The element strontium was primarily used in the production of glass for color TVs and computer monitors, thanks to its X-ray-shielding properties. It can also give fireworks a deep red color.

Blue was a tricky color for pyrotechnicians for some time, since the traditional material used, copper chloride, didn’t survive well enough at high heat to produce a vibrant display. But in recent decades, makers of fireworks have found success with a magnesium-aluminum alloy called magnalium.

Other substances besides the color-generating material are also used in fireworks. To slow or speed the burn rate, pyrotechnicians can add sulfur or sugars (to make it burn faster) or salt (to slow it down).