There are lots of chemicals called ‘hydrocarbons’ which (as the name suggests) are made of hydrogen and carbon. The hydrogen and carbon join up into really strong chains. Different length chains are different types of flammable ‘stuff’ you may have heard of: for example methane, ethane, butane, propane… Petrol and diesel are just mixtures of all these types of hydrocarbon.
When you burn a hydrocarbon (like petrol), you’re splitting apart the chemical bonds between carbon and hydrogen atoms. This splitting apart releases lots of energy in the form of flames!