Aims/hypothesis We aimed to investigate the associations between maternal diabetes before or during pregnancy and the risk of high refractive error (RE) in offspring until the age of 25 years. Methods This nationwide register-based cohort study comprised 2,470,580 individuals born in 1977-2016. The exposure was maternal diabetes during or before pregnancy (type 1 diabetes, type 2 diabetes and gestational diabetes). Cox regression was used to examine the association between maternal diabetes and the risk of high RE in offspring from birth until the age of 25 years, adjusting for multiple potential confounders. Results During up to 25 years of follow-up, 553 offspring of mothers with diabetes and 19,695 offspring of mothers without diabetes were diagnosed with high RE. Prenatal exposure to maternal diabetes was associated with a 39% increased risk of high RE: HR 1.39 (95% CI 1.28, 1.51), p < 0.001; standardised cumulative incidence in unexposed offspring at 25 years of age 1.18% (95% CI 1.16%, 1.19%); cumulative incidence difference 0.72% (95% CI 0.51%, 0.94%). The elevated risks were observed for hypermetropia (HR 1.37 [95% CI 1.24, 1.51], p < 0.001), myopia (HR 1.34 [95% CI 1.08, 1.66], p = 0.007) and astigmatism (HR 1.58 [95% CI 1.29, 1.92], p < 0.001). The increased risks were more pronounced among offspring of mothers with diabetic complications (HR 2.05 [95% CI 1.60, 2.64], p < 0.001), compared with those of mothers with diabetes but no diabetic complications (HR 1.18 [95% CI 1.02, 1.37], p = 0.030). Conclusions/interpretation Our findings suggest that maternal diabetes during pregnancy is associated with an increased risk of high RE in offspring, in particular among those of mothers with diabetic complications. Early ophthalmological screening should be recommended in offspring of mothers with diabetes diagnosed before or during pregnancy.