Imaging dense and diverse microbial communities has broad applications in basic microbiology and medicine, but remains a grand challenge due to the fact that many species adopt similar morphologies. While prior studies have relied on techniques involving spectral labeling, we have developed an expansion microscopy method (μExM) in which bacterial cells are physically expanded prior to imaging. We find that expansion patterns depend on the structural and mechanical properties of the cell wall, which vary across species and conditions. We use this phenomenon as a quantitative and sensitive phenotypic imaging contrast orthogonal to spectral separation to resolve bacterial cells of different species or in distinct physiological states. Focusing on host-microbe interactions that are difficult to quantify through fluorescence alone, we demonstrate the ability of μExM to distinguish species through an in vitro defined community of human gut commensals and in vivo imaging of a model gut microbiota, and to sensitively detect cell-envelope damage caused by antibiotics or previously unrecognized cell-to-cell phenotypic heterogeneity among pathogenic bacteria as they infect macrophages.