The course of immune maturation has evolved to favour survival at each stage of development in early life. Fetal and neonatal immune adaptations facilitate intrauterine survival and provide early postnatal protection against extracellular pathogens, but they leave infants susceptible to intracellular pathogens such as viruses that are acquired perinatally. This Review focuses on three such pathogens--HIV, hepatitis B virus and cytomegalovirus--and relates the differential impact of these infections in infants and adults to the antiviral immunity that is generated at different ages. A better understanding of age-specific antiviral immunity may inform the development of integrated prevention, treatment and vaccine strategies to minimize the global disease burden resulting from these infections.