Pancreatic-insufficient children with cystic fibrosis (CF) receive age-group-specific vitamin D supplementation according to international CF nutritional guidelines. The potential advantageous immunomodulatory effect of serum 25-hydroxy vitamin D (25(OH)D) on pulmonary function (PF) is yet to be established and is complicated by CF-related vitamin D malabsorption. We aimed to assess whether current recommendations are optimal for preventing deficiencies and whether higher serum 25(OH)D levels have long-term beneficial effects on PF. We examined the longitudinal relationship between vitamin D intake, serum 25(OH)D and PF in 190 CF children during a 4-year follow-up period. We found a significant relationship between total vitamin D intake and serum 25(OH)D (β = 0·02; 95 % CI 0·01, 0·03; P = 0·000). However, serum 25(OH)D decreased with increasing body weight (β = –0·79; 95 % CI –1·28, –0·29; P = 0·002). Furthermore, we observed a significant relationship between serum 25(OH)D and forced expiratory volume in 1 s (β = 0·056; 95 % CI 0·01, 0·102; P = 0·018) and forced vital capacity (β = 0·045; 95 % CI 0·008, 0·082; P = 0·017). In the present large study sample, vitamin D intake is associated with serum 25(OH)D levels, and adequate serum 25(OH)D levels may contribute to the preservation of PF in children with CF. Furthermore, to maintain adequate levels of serum 25(OH)D, vitamin D supplementation should increase with increasing body weight. Adjustments of the international CF nutritional guidelines, in which vitamin D supplementation increases with increasing weight, should be considered.