Electrochemical reduction of oxygen molecules can produce H2O2, which is an important chemical for a green and sustainable society; therefore, the development of catalysts for this reaction is necessary. We propose mesoporous nitrogen-doped carbon prepared from (1-methyl-1H-pyrrole-2-yl)methanol in the presence of a mesoporous SiO2 template (KIT-6). The nitrogen content of the resulting carbon can be controlled in the range of 0?10 at.?% and all prepared samples have well-ordered mesopores with diameters of 3.4?4.0 nm. Electrochemical studies indicate the present materials have high catalytic activities with high selectivity toward H2O2 over 90%. Such high selectivity toward H2O2 is probably due to good mass transport in the catalyst layer, which is enhanced by the mesoporous structure.