Despite documented mental illness-related disparities in cervical cancer screening and incidence, insufficient data exist on differences in cervical cancer prevention strategies, such as human papillomavirus (HPV) vaccination. We aimed to investigate the association of mental illness and neurodevelopmental conditions among girls and their parents with uptake of HPV vaccination in Sweden. This population-based cohort study was based on the Swedish school-based HPV vaccination programme, which offers the first vaccine dose to girls aged 10-13 years, with a second dose offered within 12 months. We identified all girls born between Jan 1, 2002, and March 1, 2004, using the Swedish Total Population Register-ie, those eligible for two vaccine doses in the vaccination programme from its initiation in autumn 2012, to March, 2019. Nationwide Swedish register data (National Patient Register, Prescribed Drug Register, HPV Vaccination Register, National Vaccination Register, Total Population Register, Multi-Generation Register, Longitudinal Integrated Database for Health Insurance and Labour Market Studies, Education Register, National Cervical Screening Registry, and Cancer Register) were used to define individual and parental mental health conditions, including mental illness and neurodevelopmental conditions (defined by a clinical diagnosis and prescribed psychotropic medication use), HPV vaccine uptake (first and second dose), and sociodemographic and clinical characteristics. The two outcomes were uptake of the first HPV vaccine dose by the girl's 14th birthday and uptake of the second dose by the 15th birthday in relation to individual and parental mental health conditions, calculated using multivariable Poisson regression models. 115 104 girls were included in the study population. 2211 girls (1·9%) had a specialist diagnosis of any mental health condition. Uptake of the first HPV vaccine dose was 80·7% (92 912 of 115 104) and was lower among girls with versus without any mental health condition (adjusted relative risk 0·89 [95% CI 0·87-0·91]). The diagnosis of autism (0·79 [0·75-0·85]) or intellectual disability (0·78 [0·73-0·83]) were most strongly associated with lower HPV vaccine uptake. Vaccine uptake was also lower among girls with versus those without prescribed use of psychotropic medication (0·93 [0·92-0·95]), with the strongest association observed for antipsychotics (0·68 [0·56-0·82]). Uptake of the second dose was 95·0% (88 308 of 92 912), with no strong associations between uptake and mental health conditions in girls or their parents. Our findings suggest disparities in cervical cancer prevention among girls with mental health conditions, and call for further research to ensure equitable protection. Swedish Cancer Society.