KnowHow team explains: Flame colour is produced from the movement of electrons in the metal ions present in the burning material. When you heat the material, the electrons gain energy and jump to a higher level. However, they jump back to their initial level to maintain the stability. For this, each of these electrons releases the excess energy. Each jump involves a specific amount of energy being released as light energy, and each corresponds to a particular colour. As a result of all these jumps, a spectrum of coloured lines is formed. The colour you see will be a combination of all these individual colours. The exact sizes of the possible jumps in terms of energy vary from one metal ion to another. This means each ion will have a different pattern of spectral lines, and thus a different flame colour.
The strong orange colour of most wood flames results when the sodium in the wood is heated. The temperature of wood flames is lower than that of candle flames, which is why the colour of wood flames is orange, not yellow. If, however, some of the carbon particles in the fire are very hot, the colour will be yellow. The product of the burnt carbon, when it has cooled, is black soot.
Since fire needs oxygen to burn, and since the bottom of a candle flame does not get much oxygen, it is the hottest spot in the flame and is blue in colour.
The flame cools and changes colour as it moves away from the source of the flame, because it is exposed to more oxygen. The temperature change causes the colour of the flame to change from blue to the typical, bright, yellowish-orange or bright orange. Which shade of orange is seen at the upper portion of the flame depends on the material being burnt.