Lithium–sulfur (Li–S) batteries have great potential as an electrochemical energy storage system because of the high theoretical energy density and acceptable cost of financial and environment. However, the shuttle effect leads to severe capacity fading and low coulombic efficiency. Here, graphitic carbon nitride (g–C3N4) is designed and prepared via a feasible and simple method from trithiocyanuric acid (TTCA) to anchor the polysulfides and suppress the shuttle effect. The obtained g–C3N4 exhibits strong chemical interaction with polysulfides due to its high N–doping of 56.87 at%, which is beneficial to improve the cycling stability of Li–S batteries. Moreover, the novel porous framework and high specific surface area of g–C3N4 also provide fast ion transport and broad reaction interface of sulfur cathode, facilitating high capacity output and superior rate performance of Li–S batteries. As a result, Li–S batteries assembled with g–C3N4 can achieve high discharge capacity of 1200 mAh/g at 0.2 C and over 800 mAh/g is remained after 100 cycles with a coulombic efficiency more than 99.5%. When the C–rate rises to 5 C, the reversible capacity of Li–S batteries can still maintain at 607 mAh/g.