Bacterial biofilms represent an important medical problem; however, the mechanisms of the onset of biofilm formation are poorly understood. Here, using new controlled methods allowing high-throughput and reproducible biofilm growth, we show that biofilm formation is linked to self-imposed mechanical stress. In growing uropathogenic Escherichia coli colonies, we report that mechanical stress can initially emerge from the physical stress accompanying colony confinement within micro-cavities or hydrogel environments reminiscent of the cytosol of host cells. Biofilm formation can then be enhanced by a nutrient access-modulated feedback loop, in which biofilm matrix deposition can be particularly high in areas of increased mechanical and biological stress, with the deposited matrix further enhancing the stress levels. This feedback regulation can lead to adaptive and diverse biofilm formation guided by the environmental stresses. Our results suggest previously unappreciated mechanisms of the onset and progression of biofilm growth.