Morphogens control patterns of transcription in development, often by establishing concentration gradients of a single transcriptional activator. However, many morphogens, including Hedgehog, create opposing activator and repressor gradients (OARGs). In contrast to single activator gradients, it is not well understood how OARGs control transcriptional patterns. We present a general thermodynamic model that explains how spatial patterns of gene expression are established within OARGs. The model predicts that differences in enhancer binding site affinities for morphogen-responsive transcription factors (TFs) produce discrete transcriptional boundaries, but only when either activators or repressors bind cooperatively. This model quantitatively predicts the boundaries of gene expression within OARGs. When trained on experimental data, our model accounts for the counterintuitive observation that increasing the affinity of binding sites in enhancers of Hedgehog target genes produces more restricted transcription within Hedgehog gradients in Drosophila. Because our model is general, it may explain the role of low-affinity binding sites in many contexts, including mammalian Hedgehog gradients.