International studies show that school food programmes (SFP) can improve children’s diets but evidence from Canada is nascent. We examined whether SFP are linked to better dietary intake and diet quality among Canadian elementary schoolchildren. This cross-sectional study surveyed 2366 grade 4–8 students (age 9–14 years; 48·9 % girls) from 32 schools in socioeconomically disadvantaged communities in Alberta and Ontario, Canada. Students completed a 24-hour diet recall, recording foods and beverages consumed during school hours (breakfast, morning snack, lunch, afternoon snack), and their source (school, other). Multivariable linear models examined the association of accessing SFP (≥1 meal/snack provided by school) with student daily intakes of vegetables and fruit, grains and grain products, milk and alternatives, meat and alternatives, free sugars, sodium and diet quality, adjusting for relevant confounders. Only 293 (12·4 %) students accessed SFP. Overall, accessing SFP was associated with higher intake of vegetables and fruit (β = 0·4, 95 % CI = 0·1; 0·7) and better diet quality score (β = 1·8, 95 % CI = 0·7; 3·0). Specifically, morning snacks provided by schools were associated with lower intake of free sugars (β = –8·9, 95 % CI = –16·5; −1·4), while school-provided lunches were associated with higher intake of milk and alternatives (β = 0·5, 95 % CI = 0·2; 0·8). Further, school-provided afternoon snacks were associated with higher intake of vegetables and fruit (β = 1·1, 95 % CI = 0·6; 1·6), lower sodium intake (β = –258·4, 95 % CI = –506·7; −10·0) and better diet quality (β = 3·1, 95 % CI = 1·1; 5·1). One in eight elementary schoolchildren accessed SFP. Students who accessed SFP had better diets, highlighting the potential of SFP (particularly snacks) in improving children’s diets.