The electronic and optical properties of g-C3N4/TiO2 heterostructure are investigated using spin-polarized DFT+U calculations. The equilibrium spacing (1.94 Å) and binding energy (24 meV/Å2) show that g-C3N4/TiO2 is a van der Waals heterostructure. And the calculated band gap of g-C3N4/TiO2 is significantly reduced compared with TiO2. Therefore, the visible light response of g-C3N4/TiO2 heterostructure is remarkably improved. Besides, the predicted type II band alignment would ensure that the electrons can migrate from g-C3N4 monolayer to anatase TiO2 (101) surface, which leads oxidation and redox reactions can occur on g-C3N4 and TiO2, respectively. Finally, a built-in electric field within the interface region will be set. Above processes can benefit the separation of photoexcited carriers and enhance the hydrogen-evolution activity. In addition, compared with TiO2, g-C3N4/TiO2 with higher conduction band minimum energy can effectively produce higher-energy electrons to reduce hydrogen ions. Moreover, the influence of composite distance and the number of g-C3N4 layers are also investigated systematically. The results indicate that the optical absorption is enhanced over the whole spectrum with the increase of the number of g-C3N4 layers. Similar visible light enhancing is also found when the composite distance is decreased.