Two-dimensional (2D) materials have attracted increasing interest due to their excellent properties and various applications such as energy storage, sensors, composites and catalysis. Recently, 2D van der Waals (vdW) layered materials, MoSi2N4 and WSi2N4, have been synthesized successfully by CVD methods. Here, we have investigated the structure, optoelectronic properties and electron–hole excitation characteristics of two-dimensional MoSi2N4, MoSi2P4, and WSi2N4 using first-principles calculations to determine whether they can be applied for photocatalytic hydrolysis. The results showed that replacing N atoms in 2D MoSi2N4 with P atoms could not only reduce the bandgap, but also make the band position more negative, while replacing Mo atoms with W atoms could expand and move the bands towards more positive direction. H+ ions can obtain electrons to generate H2 from the conduction band of WSi2N4 where the conduction band minimum (CBM) and valence band maximum (VBM) is –0.43 and –2.49 eV, respectively. Time-dependent density functional theory is used to explain that the experimentally measured UV–Vis spectra in which visible light absorption is broader and more intense in WSi2N4 than in MoSi2N4 and WSi2N4 is a promising photocatalyst for H2 generation from water.