A colour for each metal
Firework colours come from metals. According to the USGS, strontium gives red, sodium yellow, barium green and copper blue.
The Royal Society of Chemistry explains the basic idea. Strong oxidising agents in the mixture supply enough heat to excite an electron in the colour-producing chemicals, and that leads them to give off light. The colour you see is that emission.
The delicate one
The Royal Society of Chemistry says blue has always been a difficult colour for firework makers. The copper chloride molecule (CuCl2) that creates it is delicate and is easily destroyed at high temperatures.
Because of that, the oxidiser used has to be chosen carefully.
Mixing and extras
The USGS notes that mixtures give other colours: strontium with sodium makes orange, and copper with strontium makes purple or lavender.
Silvery white comes from titanium, zirconium and magnesium alloys, and gold sparks from iron filings and charcoal. Aluminium powder produces the bright flashes and loud bangs.

