The surface stiffness of the microenvironment is a mechanical signal regulating biofilm growth without the risks associated with the use of bioactive agents. However, the mechanisms determining the expansion or prevention of biofilm growth on soft and stiff substrates are largely unknown. To answer this question, we used PDMS (polydimethylsiloxane, 9–574 kPa) and HA (hyaluronic acid gels, 44 Pa–2 kPa) differing in their hydration. We showed that the softest HA inhibited Escherichia coli biofilm growth, while the stiffest PDMS activated it. The bacterial mechanical environment significantly regulated the MscS mechanosensitive channel in higher abundance on the least colonized HA-44Pa, while Type-1 pili (FimA) showed regulation in higher abundance on the most colonized PDMS-9kPa. Type-1 pili regulated the free motion (the capacity of bacteria to move far from their initial position) necessary for biofilm growth independent of the substrate surface stiffness. In contrast, the total length travelled by the bacteria (diffusion coefficient) varied positively with the surface stiffness but not with the biofilm growth. The softest, hydrated HA, the least colonized surface, revealed the least diffusive and the least free-moving bacteria. Finally, this shows that customizing the surface elasticity and hydration, together, is an efficient means of affecting the bacteria’s mobility and attachment to the surface and thus designing biomedical surfaces to prevent biofilm growth.