This is not an easy question. This is a HUGE question that is studied in great detail in the pyro community. I don't know how much detail you want, but I shall first respond to the posts above.
Jdurg's post is a very simple, and correct explanation of the phenomenon of light emission of pyrotechnic devices. If this is the level of detail you wanted, please don't read further, because the level of detail may be confusing or useless to you.
xiankai is in the right direction, but needs clarification. When we talk about metals, we are generally talking about transition metals or rare earths in their zero-oxidation state, but some metalloids like aluminum make it in there as well. Fireworks in this sense are not mostly metals. They are principally oxidizing agents, mixed with several other components. Oxidizing agents are salts, sometimes of transition metals, most often of alkali earth metals. Metals, at least those in the zero oxidation state, rarely control the color of the flame seen. Usually the color of the flame comes from metal ions, not zero-oxidation state metals. For example, strontium(II) is known to give a wonderful red color to the flame.
Now on with the details. This is only the components relevant to light production with enough background to you know what we're talking about. Fireworks are intimtate mixtures of solid components that fall into four basic categories:
1. Oxidizing agents
2. Fuels
3. Colorants
4. Halogen donors
Oxidizing agents can control temperature of the combustion, which affects color. Generally, higher temperature washes out color more.
Fuels sustain combustion. They are generally chosen as to minimize affect on color and sometimes to minimize smoke. These are generally organic compounds, but can be metals in their zero oxidation state (and are also usually the colorants in these cases)
Colorants are normally transition metal salts, such as strontium carbonate, barium chloride, cuprous chloride, or copper acetoarsenate (Paris Green) that are chosen to give the desired color. A representative list of colors with their respective metal ion is below:
Barium(II): Green (somewhat weak)
Boric acid: Green (weak)
Potassium(I): Violet (weak)
Lithium(I): Deep red
Calcium(II): Brick red/orange
Sodium(I): Yellow/Orange (normal color seen in fire)
Copper(II): Green, sometimes blue
Copper(I): Blue/Green
Strontium(II): Red
Boron(0): Deep Green
Now, if you want gold, white, or blinding white, you can choose from metals in their zero-oxidation state. These are, in order of brightlness:
Aluminum
Magnesium
Titanium
Zirconium
Halogen donors are compounds specifically added to boost the amount of available halogen ion in the flame envelope when burned. Usually the halogen is chlorine. Compounds include hexachloroethane, PVC, hexachlorobenzene and parlon. Sometimes they act as both fuel and halogen donor. Boosting the concentration of halogen in the flame envelope deepens the color of the flame considerably.
Colors themselves come from different wavelengths of light that we percieve as different colors. The basic idea is below:
Color Wavelength, nm
Infrared >700
Red 700-610
Yellow 610-570
Green 570-500
Blue 500-450
Violet 450-400
Each atom has a characteristic set of spectral wavelength lines that it emits once it is excited. By the theory of quantum mechanics, electrons can only exist at certain energy levels, meaning their energy is quantized. Those being higher in energy are more costly to maintain, so while in the high temperature region, it is easy to maintain these high energies, but as they cool down (i.e., lose energy) the electrons cannot maintain their high energy level and thus must fall back down to a lower energy level. As they fall, they emit photons of light in these characteristic wavelengths, giving us light.
If there are numerous spectral lines in the visible range, the color becomes washed out and more white looking. These are known as the atomic line spectra. They are usually not the source of pyrotechnic color, as their colors are washed out due to a continuum of energy distrubutions for the atomic ions.
We are not looking at the emission spectrum of a single ion, but rather at the emission spectrum of di- and tri-atomic ions in the same formulation with a high temperature in an ionizing atmosphere. These ions have constrained vibrational and rotational energies because they consist of multiple atoms. They have quantized vibrational and rotational energy levels and thus emit light with certain wavelengths that correspond to these levels. Molecular spectra exist over a wider range than atomic line spectra and thus give stronger bands of light.
Because these molecular spectra are what we are after for displaying light, we frequently have to add halide donors to our pyrotechnic compositions to form these molecular ions in situ. The halides of copper and alkaline earth metals like barium and strontium are some of the strongest, and thuse we seek to generate the halides of these ions in the flame envelope.
Increased temperature of the flame gives more energy to the molecules and thus causes more of the molecules to have enough energy to get promoted to higher levels and then emit light, so that is one cause of washed out color. Too low a flame temperature and you don't ionize your molecules and thus don't produce the color you want.
So, that's more than a cursory look at color without really getting into the nitty-gritty of color. Maybe it's worth my while to do an article on pyrotechnics, their color and mechanics. I dunno. Hope this answers your question to a degree.