Exposure to the shortest wavelengths in sunlight, ultraviolet light, constitutes a deleterious ecological factor for many microorganisms. The use of secondary metabolites as sunscreens has emerged as an important photoprotective mechanism in certain groups of large-celled microorganisms, such as cyanobacteria, fungi and many protists. In this Review, we describe our current understanding of microbial 'sunscreen' compounds, including scytonemin, the mycosporines and the naphthalene-based melanins. Study of these sunscreens has led to the discovery of new classes of compounds, new metabolic pathways, a deeper understanding of microbial photobiology and the potential for dermatological or biomedical applications.