Bacterial biofilms are interface-associated colonies of bacteria embedded in an extracellular matrix that is composed primarily of polymers and proteins. They can be viewed in the context of soft matter physics: the rigid bacteria are analogous to colloids, and the extracellular matrix is a cross-linked polymer gel. This perspective is beneficial for understanding the structure, mechanics, and dynamics of the biofilm. Bacteria regulate the water content of the biofilm by controlling the composition of the extracellular matrix, and thereby controlling the mechanical properties. The mechanics of well-defined soft materials can provide insight into the mechanics of biofilms and, in particular, the viscoelasticity. Furthermore, spatial heterogeneities in gene expression create heterogeneities in polymer and surfactant production. The resulting concentration gradients generate forces within the biofilm that are relevant for biofilm spreading and survival.