A novel 3D Co–Nx|P-complex-doped carbon grown on flexible exfoliated graphene foil is designed and constructed for both electrochemical and photoelectrochemical water splitting. The coordination of Co–Nx active centers hybridized with that of neighboring P atoms enhances the electron transfer and optimizes the charge distribution of the carbon surface, which synergistically promotes reaction kinetics by providing more exposed active sites.