Bacterial pathogens and commensals are surrounded by diverse surface polysaccharides which include capsules and lipopolysaccharides. These carbohydrates play a vital role in bacterial ecology and interactions with the environment. Here, we review recent rapid advancements in this field, which have improved our understanding of the roles, structures, and genetics of bacterial polysaccharide antigens. Genetic loci encoding the biosynthesis of these antigens may have evolved as bacterial diversity-generating machines, driven by selection from a variety of forces, including host immunity, bacteriophages, and cell-cell interactions. We argue that the high adaptive potential of polysaccharide antigens should be taken into account in the design of polysaccharide-targeting medical interventions like conjugate vaccines and phage-based therapies.