BackgroundThere is an urgent need for policies to address obesity and its health consequences. Children's diets lay the foundations for healthy nutrition across the life course. School meals can contribute substantially to total diet. From 2008, primary schools in England were required to comply with legislation specifying the frequency with which certain foods can and cannot be served and maximum and minimum levels of nutrients (food and nutrient based standards) in school meals. The effect of this legislation on dietary inequalities is unknown. We aimed to assess the effect of the legislation on children's mean nutrient intake at lunch and in their total diet. MethodsWe undertook cross-sectional surveys in 2003–04 (before) and 2008–09 (after legislation) in 12 primary schools in northeast England. Schools represented the socioeconomic spectrum. All children aged 4–7 years were eligible. Ethics approval and informed, written parental consent was obtained. We used a validated, prospective 4-day food diary to record children's dietary intake (n=368 in 2003–04; n=624 in 2008–09). The index of multiple deprivation 2007 was used to categorise socioeconomic status into quintiles. A linear mixed-effect model explored the effect of year, lunch type, socioeconomic status, and interactions between these factors on nutrient intake. FindingsSchool lunch uptake decreased significantly in the most deprived quintile after compared with before legislation (74% to 60%, χ2 test p=0·019). After legislation, children's mean intake from a school lunch had a lower percentage of energy from fat (difference in mean change −8·4%, 95% CI −9·9 to −6·8) and saturated fat (−4·5%, −5·4 to −3·6) and higher non-starch polysaccharides (NSPs; 1·6 g, 1·3 to 1·9) and iron (0·5 mg, 0·3 to 0·7) than those consuming a home-packed lunch. After legislation, children in the least deprived quintile had higher mean nutrient intakes from their lunch than children in the most deprived quintile (differences in mean change: NSP 0·8 g, 95% CI 0·4–1·2; iron 0·4 mg, 0·2–0·6; zinc 0·3 mg, 0·1–0·5). After legislation, children's mean micronutrient intakes in their total diet increased in the least deprived quintile and fell in the most deprived quintile (differences in mean change: NSP 1·2 g, 95% CI 0·3–2·1; iron 0·9 mg, 0·3–1·5; zinc 0·64 mg 0·3–1·0). For children consuming a school lunch, mean total dietary intake of vitamin C increased across all quintiles but increased more for children in the most deprived quintile; for children consuming a home-packed lunch, mean vitamin C intake fell in the most deprived quintile and increased in the least deprived quintile (p=0·035). A key limitation was the use of repeated cross-sectional surveys and lack of control group, which limits the extent to which changes in nutrient intakes can be fully attributed to the implementation of the school food legislation. InterpretationThis legislation has led to children who consume school lunches having a healthier mean nutrient profile than those who consume home-packed lunches. Nutrient intakes have improved overall for the most deprived children. However, inequalities in micronutrient intakes persist at lunchtime and in total diet regardless of lunch type. Additional interventions are needed: for the most deprived families, uptake of school lunch needs to be encouraged; for all children, guidance is needed on how to make the healthiest choices from the foods offered. FundingThis work was undertaken as part of the research programme of the Public Health Research Consortium, which is funded by the Department of Health Policy Research Programme. The views expressed in this publication are those of the authors. MW and AJA are partly funded as members of Fuse, the Centre for Translational Research in Public Health, a UK Clinical Research Collaboration (UKCRC) Public Health Research Centre of Excellence. We thank the British Heart Foundation, Cancer Research UK, Economic and Social Research Council, MRC, and the NIHR, under the auspices of the UKCRC for funding. AJA is funded by a NIHR Professorship.