• The adsorption behavior of F-modified g-C 3 N 4 towards various gases is probed. • Interior F doped C 3 N 4 possesses thermal stability and high NO capture capacity. • Electron vacancies engendered by F are responsible for NO capture. Effective capture of NO molecule is of great significance for its environmental removal and separation. In present work, theoretical calculations based on density functional theory (DFT) were implemented to investigate the adsorption performances and interaction mechanism of the surface and interior fluorine (F) doped C 3 N 4 towards gases. The results showed that although the surface F doped C 3 N 4 possessed excellent selectivity for NO among O 2 , N 2 , CO, CO 2 , NO and NO 2, an undesired byproduct—nitrosyl fluoride (FNO) has yielded in the adsorption process. While the interior F-doped C 3 N 4 effectively prevented the FNO generation, and retained the high selectivity and adsorption capacity for NO. The superior adsorption characteristics originated from the electron vacancies engendered in the F-doped C 3 N 4 surface attributed from the strong electronegativity of F atoms. In addition, the optical properties and the effect of F concentration were explored. The visible-light response range was enlarged after NO adsorption, which was conducive to detect NO molecules. And decreasing the concentration of fluorine greatly reduced the affinity and intensity for NO adsorption, offering an efficient way to tune the NO capture ability. Our work anticipates a wide range of potential applications of F-modified carbon nitride in the capture and detection of NO.