We present a capillary pinning technique that gives complete control on the local patterning of hydrogel structures in closed microchips. The technique relies on selective trapping of liquids at predefined locations in a microchip using capillary barriers. In selective patterning, the abrupt expansion in the cross-sectional geometry of a microchannel at capillary barriers results in a confined advancement of the liquid–air meniscus. This protocol describes a detailed procedure to design and fabricate microarrays of different hydrogel types, fabricated with photopolymerization or thermogelation. The process can be subdivided into two parts. First, a PDMS microchip containing microfeatures with customized patterns is fabricated. Second, the microchip is filled with a hydrogel precursor to be cross-linked by either photopolymerization or thermogelation. The production of the microchip takes approximately 2 days, depending on the substrate selection. Preparation of the hydrogel solutions takes 1–2 h, whereas the patterning and reaction to cross-link the hydrogels is completed in a few minutes.