Forming hydrogels with precise geometries is challenging and mostly done using photopolymerization, which involves toxic chemicals, rinsing steps, solvents, and bulky optical equipment. Here, we introduce a new method for in situ formation of hydrogels with a well-defined geometry in a sealed microfluidic chip by interfacial polymerization. The geometry of the hydrogel is programmed by microfluidic design using capillary pinning structures and bringing into contact solutions containing hydrogel precursors from vicinal channels. The characteristics of the hydrogel (mesh size, molecular weight cut-off) can be readily adjusted. This method is compatible with capillary-driven microfluidics, fast, uses small volumes of reagents and samples, and does not require specific laboratory equipment. Our approach creates opportunities for filtration, hydrogel functionalization, and hydrogel-based assays, as exemplified by a rapid, compact competitive immunoassay that does not require a rinsing step.