A non-toxic hydrolytically fast-degradable antibacterial hydrogel is herein presented to preemptively treat surgical site infections during the first crucial 24 h period without relying on conventional antibiotics. The approach capitalizes on a two-component system that form antibacterial hydrogels within 1 min and consist of i) an amine functional linear-dendritic hybrid based on linear poly(ethylene glycol) and dendritic 2,2-bis(hydroxymethyl)propionic acid, and ii) a di-N-hydroxysuccinimide functional poly(ethylene glycol) cross-linker. Broad spectrum antibacterial effect is achieved by multivalent representation of catatonically charged β-alanine on the dendritic periphery of the linear dendritic component. The hydrogels can be applied readily in an in vivo setting using a two-component syringe delivery system and the mechanical properties can accurately be tuned in the range equivalent to fat tissue and cartilage (G' = 0.5-8 kPa). The antibacterial effect is demonstrated both in vitro toward a range of relevant bacterial strains and in an in vivo mouse model of surgical site infection.