The electrosynthesis of hydrogen peroxide (H2O2) has been widely considered as an environmentally friendly and sustainable alternative to the conventional anthraquinone protocol. Covalent organic frameworks (COFs) have emerged as promising metal-free catalysts for oxygen reduction reaction (ORR) processes. The designable molecular structures of COFs render adjustable catalytic selectivity towards two-electron (2e−) ORR pathway for the electrosynthesis of H2O2. Here, we synthesized a viologen-linked cationic COF, namely PTBD, via Zincke reaction using a conventional solvothermal strategy. To investigate the correlation between the structure and the catalytic performance, imine-linked neutral COFs of PTBP and PBBP with varying heteroatom nitrogen contents are prepared via Schiff-base condensation reaction. Notably, the PTBD COF, which is constructed by di-cationic viologen linkages and triazine blocks, delivers an exceptional H2O2 selectivity of ~92%, considerably surpassing the imine-bridged neutral PTBP (~30%) and PBBP (~78%) COFs. Theoretical calculations are performed to uncover how the thermodynamic tendency of PTBD COF towards 2e− ORR route is related to its proper activation of O2. This work highlights the role of linkage and heteroatom contents in COFs regarding the catalytic selectivity, paving a way for designing metal-free catalysts for the selective electrosynthesis of H2O2.