BackgroundSelective serotonin reuptake inhibitors (SSRIs) are the most frequently prescribed antidepressants in pregnancy. Animal and some clinical studies have suggested potential increases in depression and anxiety following prenatal SSRI exposure, but the extent to which these are driven by the medication remains unclear. We used Danish population data to test associations between maternal SSRI use during pregnancy and children outcomes up to age 22.MethodsWe prospectively followed 1,094,202 single-birth Danish children born 1997–2015. The primary exposure was ≥ 1 SSRI prescription filled during pregnancy; the primary outcome, first diagnosis of a depressive, anxiety, or adjustment disorder, or redeemed prescription for an antidepressant medication. We used propensity score weights to adjust potential confounders, and incorporated data from the Danish National Birth Cohort (1997–2003) to further quantify potential residual confounding by subclinical factors.ResultsThe final dataset included 15,651 exposed and 896,818 unexposed, children. After adjustments, SSRI-exposed had higher rates of the primary outcome than those of mothers who either did not use an SSRI (HR = 1.55 [95%CI:1.44,1.67] or discontinued the SSRI use ≥ 3 months prior to conception (HR = 1.23 [1.13,1.34]). Age of onset was earlier among exposed (9 [IQR:7–13] years) versus unexposed (12 [IQR:12–17] years) children (p < 0.01). Paternal SSRI use in the absence of maternal use during the index pregnancy (HR = 1.46 [1.35,1.58]) and maternal SSRI use only after pregnancy (HR = 1.42 [1.35,1.49]) were each also associated with these outcomes.ConclusionsWhile SSRI exposure was associated with increased risk in the children, this risk may be driven at least partly by underlying severity of maternal illness or other confounding factors.Supplementary InformationThe online version contains supplementary material available at 10.1186/s13034-023-00624-9.