Two-dimensional (2D) carbon materials have attracted enormous attention, but the complicated synthesis methods, inhomogeneous structure and uncontrollable properties still limit their use. Here we report a universal protocol for fabricating a series of heteroatom-doped 2D porous polymers, including pyrrole and indole as nitrogen-dopant sources, and 3,4-ethoxylene dioxy thiophene as a sulfur-dopant source by a simple chemical crosslinking reaction. This bottom-up strategy allows for the large-scale synthesis of functionalized ultrathin carbon nanosheets with a high heteroatom doping content and abundant porosity. Consequently, the obtained N-doped carbon-rich nanosheets (NCNs) sample has a specific capacity of 573.4 mAh g−1 at 5 A g−1 as an anode for lithium-ion capacitors (LICs), and the optimized sample has a specific capacitance of 100.0 F g−1 at 5 A g−1 when used as a cathode for a LIC. A dual-carbon LIC device was also developed that had an energy density of 168.4 Wh kg−1 at 400 W kg−1, while maintaining outstanding cycling stability with a retention rate of 86.3% after 10 000 cycles. This approach has the potential to establish a way for the precise synthesis of substantial amounts of 2D functionalized carbon nanosheets with the desired structure and properties.