Light a match and, while it’s burning, twist it into a variety of positions. The flame keeps pointing unerringly upward, regardless of the orientation of its fuel. How, indeed, does it “know”?
You are well aware that hot air rises. A flame, whatever it is, must therefore be carried upward by the rising current of hot air. And that’s all we need to know about why flames go upward.
But a more challenging question is, What is a flame? Is it the rising air itself, glowing from the heat? Nope.
A flame is a region of space in which a chemical reaction is going on: combustion, a reaction between the oxygen in the air and a flammable gas.
Did I say gas? Yes. But don’t solids and liquids burn with flames also? Yes. (And when will I stop asking questions of myself?)
Wood and coal are solids, and they are indeed flammable; gasoline and kerosene are liquids, and they are indeed flammable. But none of them will actually burn until they have been converted into a gas or vapor. It’s their vapors that burn, because only vapors can mix into the air intimately enough to rub elbows, rub molecules, that is, with the air’s oxygen.
Molecules can’t react unless they actually come into contact with one another. The oxygen gas in the air can’t penetrate the solid or liquid fuel, so the fuel must vaporize and go out to meet the oxygen. That’s why we have to light a fire. We have to get the fuel hot enough in at least one small location, so it will vaporize. Once the vapor starts burning, the heat of combustion, the combustion reaction releases heat, keeps vaporizing more and more fuel and keeps the process going until all the fuel is gone. (Provided that there is an inexhaustible supply of oxygen.)
A fuel that is already a vapor, such as the methane in our kitchen gas ranges, has no trouble mixing with the air, so it can be ignited by a mere spark. Propane-burning gas grills and butane-burning cigarette lighters contain those fuels in the liquid form, under pressure. But as soon as they are released, they vaporize into gases and mix into the air, whereupon they can also be ignited easily by a spark.
When we light a candle with a match, the match first has to melt a bit of the wax, the liquefied wax must travel up the wick by capillary attraction, and the match must vaporize some of that liquid. Only then can the wax vapor mix with the air and ignite. Without a wick to conduct the liquefied wax up to where there is a good air supply, a candle won’t burn.
But if a flame is simply two invisible gases reacting with each other, how come we can see it? In the case of a candle, the flame is visible because oxygen can’t flow in fast enough to react completely with all of the rapidly vaporizing wax. So some wax remains unburned as tiny particles of carbon, glowing yellow from the heat and swept upward by the current of hot air.
As the crowd of glowing carbon particles rises higher, the oxygen nibbles away at its outer edges, burning particles up completely into invisible carbon dioxide gas. The crowd of glowing particles is thus depleted more and more as it rises. That’s why a candle flame tapers off toward its upper end.