Hollow carbon nitride spheres with a well-designed architecture and excellent optical properties serve as promising polymers for solar fuel production. In this study, carbon-rich hollow carbon nitride nanospheres were rationally designed for photocatalytic hydrogen peroxide production. Experimental results revealed that the doping of carbon species in the heptazine unit enhanced light absorption and promoted charge separation and transport. Accordingly, the optimized carbon-rich hollow carbon nitride nanospheres exhibited significantly enhanced photocatalytic performance for solar-driven hydrogen peroxide production and Cr(VI) reduction in comparison with pristine polymeric carbon nitride and hollow carbon nitride nanospheres.