Heteroatom-doped carbon materials, in which non-carbon elements such as nitrogen, phosphorus, sulphur or boron are incorporated into graphitic frameworks, have emerged as versatile electrocatalysts.