To examine the association of maternal prepregnancy diabetes, gestational diabetes mellitus (GDM), and 12 subtypes of congenital anomalies of the newborn.We included 29,211,974 live births with maternal age ranging from 18 to 49 years old documented in the National Vital Statistics System in the U.S. from 2011 to 2018. Information on prepregnancy diabetes, GDM, and congenital anomalies was retrieved from birth certificates. Log-binomial regression was used to estimate risk ratios (RRs) and 95% CIs for congenital anomalies overall and by subtypes.Of the 29,211,974 live births, there were 90,061 infants who had congenital anomalies identified at birth. The adjusted RRs of congenital anomalies at birth were 2.44 (95% CI 2.33-2.55) for prepregnancy diabetes and 1.28 (95% CI 1.24-1.31) for GDM. The association were generally consistent across subgroups by maternal age, race/ethnicity, prepregnancy obesity status, and infant sex. For specific subtypes of congenital anomalies, maternal prepregnancy diabetes or GDM was associated with an increased risk of most subtypes. For example, the adjusted RRs of cyanotic congenital heart disease were 4.61 (95% CI 4.28-4.96) for prepregnancy diabetes and 1.50 (95% CI 1.43-1.58) for GDM; the adjusted RRs of hypospadias were 1.88 (95% CI 1.67-2.12) for prepregnancy diabetes and 1.29 (95% CI 1.21-1.36) for GDM.Prepregnancy diabetes and, to a lesser extent, GDM were associated with several subtypes of congenital anomalies of the newborn. These findings suggest potential benefits of preconception counseling in women with pre-existing diabetes or at risk for GDM for the prevention of congenital anomalies.