In this work, one-step pyrolysis of molten urea and formaldehyde was adopted to introduce O atom, C and N defects in polymeric carbon nitride (CN) for tuning its electronic structures. Results confirmed that the introduced C, N-defects and O dopant could increase the light absorption (440–640 nm) and suppressed the photogenerated charge recombination of CN. The calculated free energies for H* adsorption revealed that the intrinsic H2 evolution activity of C, N-deficient and O-doped CN increased. Accordingly, the optimal sample exhibited an excellent photocatalytic H2 evolution rate (HER) of 18.95 mmol g−1 h−1 in 10% triethanolamine solution under visible light irradiation (1% Pt as a cocatalyst), which was 6.7 times higher than that of traditional CN (2.83 mmol g−1 h−1). In addition, the HER and yield of benzaldehyde were 1.04 and 4.20 mmol g−1 h−1, respectively in 5% benzyl alcohol solution. This work provides a simple and effective strategy to tune the heptazine and electronic structure of CN for large increasing its photocatalytic activity.