Lithium–sulfur (Li–S) batteries are promising candidates for next-generation energy storage systems owing to their high energy density and low cost. However, critical challenges including severe shuttling of lithium polysulfides (LiPSs) and sluggish redox kinetics limit the practical application of Li–S batteries. Carbon nitrides (CxNy), represented by graphitic carbon nitride (g-C3N4), provide new opportunities for overcoming these challenges. With a graphene-like structure and high pyridinic-N content, g-C3N4 can effectively immobilize LiPSs and enhance the redox kinetics of S species. In addition, its structure and properties including electronic conductivity and catalytic activity can be regulated by simple methods that facilitate its application in Li–S batteries. Here, the recent progress of applying CxNy-based materials including the optimized g-C3N4, g-C3N4-based composites, and other novel CxNy materials is systematically reviewed in Li–S batteries, with a focus on the structure–activity relationship. The limitations of existing CxNy-based materials are identified, and the perspectives on the rational design of advanced CxNy-based materials are provided for high-performance Li–S batteries.