Firecrackers and sparklers function somewhat similarly to the large aerial fireworks you frequently see at 4th of July celebrations. Firecrackers are made up of gunpowder wrapped in a tight paper tube with a fuse attached. The gunpowder contains charcoal, sulfur, and potassium nitrate. For a brighter explosion, aluminum might also be used.
Sparklers are composed differently than fireworks because their purpose is to burn continuously for a time rather than give off a sudden and brief explosion. Sparklers must contain a fuel, an oxidizer, iron or steel powder, and a binder. The oxidizer is frequently potassium nitrate while the fuel is usually charcoal and sulfur. The binder used can be sugar or starch. These ingredients are combined in such a way that causes the sparkler to burn more slowly.
Aerial fireworks, while similar in ingredients, require a few additional elements. These fireworks come in something called a shell. The shell has four parts: the container, stars, bursting charge, and the fuse. Just below the shell is a cylinder that provides the charge that will lift the firework into the air. The fireworks are launched from something called a mortar. The mortar is frequently made from a steel tube with some gunpowder in the base which is lit to provide a lifting charge.
Aerial fireworks can have any combination of shells and casings that allow them to explode in different ways. With all of these chemicals acting together, it is no wonder that we leave our colorful firework shows in the hands of professionals!
If you want to read more about how fireworks work and how different types of casings can allow for different explosions, go to http://science.howstuffworks.com/innovation/fireworks1.htm