This study aimed to investigate the optimal degree of weight gain across the gestational spectrum in 1971 children enrolled at birth and followed up to age 7 years. Weight gain in infancy was categorized into four groups based on weight gain z-scores: slow (<-0.67), on track (-0.67 to 0.67), rapid (0.67 to 1.28), and extremely rapid (>1.28). Underweight and overweight or obesity (OWO) were defined as a body mass index ≤5(th) and ≥85(th) percentile, respectively, for age and gender. In our population, OWO was far more common than underweight (39.7% vs. 3.6%). Weight gain tracked strongly from age 4 to 24 months, and was positively associated with OWO and an unfavorable pattern of metabolic biomarkers, although the degree of weight gain for the risk was different across gestational categories. Extremely rapid weight gain led to a particularly high risk of OWO among children born early term and late preterm: odds ratio: 3.3 (95% confidence interval: 1.9 to 5.5) and 3.7 (1.8 to 7.5), respectively, as compared to those with on track weight gain. Our findings suggest that monitoring and ensuring optimal weight gain across the entire gestational spectrum beginning from birth represents a first step towards primary prevention of childhood obesity.