Hierarchically porous carbons with variable pore sizes at multi-length-scale, a nitrogen and boron co-doped and local graphitized framework, and high mechanical strength were synthesized through the self-assembly of poly(benzoxazine-co-resol) with ionic liquid C16mimBF4 and a carbonization process. In this synthesis, the ionic liquid acts both as a structure directing agent and a heteroatom precursor. The obtained porous carbons have a specific surface area lower than 376 m2 g−1 and thus a high skeleton density. With such heteroatom doped skeleton structures and fully interconnected macropores, mesopores and micropores, the hierarchically porous carbon shows outstanding electrochemical performance, e.g. a superior high gravimetric capacitance (Cg) of 247 F g−1, an interfacial capacitance (CS) of 66 μF cm−2 (calculated based on the discharge curve with a constant current density of 0.5 A g−1), whilst a high volumetric capacitance (Cv) of 101 F cm−3 compared to those reported in the literature. Cycling stability tests indicate that the carbon exhibits a capacitance retention of ∼96.2% after 4000 charge–discharge cycles, strongly reflecting an excellent long-term cyclability of the electrode. Due to its unique skeleton structure and high conductivity, such hierarchically porous carbon shows promise as an electrode material for supercapacitors.
