For the first time, high surface area uniformly nitrogen (N)- and boron-nitrogen (BN)-decorated nanoporous carbons have been successfully fabricated by impregnation of ionic liquids (ILs) within a metal-organic framework (MOF), MIL-100(Al), followed by carbonization, which exhibit remarkable CO2 and H2 adsorption capacities.