Coping with the gradually increasing worldwide energy and environmental issues, it is urgent to develop efficient, cheap and visible-light-driven photocatalysts for hydrogen production. Here, we present a facile way to synthesize bromine doped graphitic carbon nitride (CN-BrX) with highly porous structure by using ionic liquid (1-butyl-3-vinylimidazolium bromide) as the Br source and soft-template for the first time, which applied in hydrogen evolution under visible light irradiation. A systematic study is conducted on the optimization in the doping amount. The results find that the as-fabricated CN-BrX photocatalysts possess a uniform porous network with thin walls due to the release of volatile domains and decomposition of ionic liquids. The highly porous structure with the large surface area (≤150 m2/g) benefits the exposure of active sites. Moreover, the bromine modification and porous structure can narrow the band gap, enhance the transportation capability of photogenerated electrons, improve the optical and conductive properties of CN, thus contribute to an outstanding H2 evolution rate under visible light irradiation (120 μmol h−1), which is about 3.6 times higher than pure CN. This work provides a new insight for designing the novel g-C3N4 based photocatalysts for hydrogen production, CO2 conversion and environmental remediation.