The first fireworks were made in China over a thousand years ago. They used the newly invented black powder as a propellant for rockets and as a noisemaker.
You need two things to make an exploding firecracker from black powder. You need the powder, and you need a closed container. Black powder by itself will just burn, it won’t explode. But if it is in a closed container, pressure will build up as it burns, until the container bursts all at once. The sudden release of all the hot gas makes a loud noise. Just like when you close a door, how much noise it makes depends on how fast you close it.
Some fireworks explode without a closed container. These don’t use black powder. Instead, they use high explosives that burn faster than the speed of sound. This is called detonating, and it breaks the sound barrier just like a jet making a sonic boom.