Human defense against infection remains a global topic. In addition to developing novel anti-infection drugs, therapeutic drug delivery strategies are also crucial to achieving a higher efficacy and lower toxicity of these drugs for treatment. The application of hydrogels has been proven to be an effective localized drug delivery approach to treating infections without generating significant systemic adverse effects. The recent emerging dynamic hydrogels further show power as injectable formulations, giving new tools for clinical treatments. In this review, we delve into the potential applications of dynamic hydrogels in antibacterial and antiviral treatments and elaborate on their molecular designs and practical implementations. By outlining the chemical designs underlying these hydrogels, we discuss how the choice of dynamic chemical bonds affects their stimulus responsiveness, self-healing capabilities, and mechanical properties. Afterwards, we focus on how to endow dynamic hydrogels with anti-infection properties. By comparing different drug-loading methods, we highlight the advantages of dynamic chemical bonds in achieving sustained and controlled drug release. Moreover, we also include the design principles and uses of hydrogels that possess inherent anti-infective properties. Furthermore, we explore the design principles and applications of hydrogels with inherent anti-infective properties. Finally, we briefly summarize the current challenges faced by dynamic hydrogels and present a forward-looking vision for their future development. Through this review, we expect to draw more attention to these therapeutic strategies among scientists working with chemistry, materials, as well as pharmaceutics.