Cases of myocarditis and pericarditis have been reported following the receipt of Covid-19 mRNA vaccines. As vaccination campaigns are still to be extended, we aimed to provide a comprehensive assessment of the association, by vaccine and across sex and age groups. Using nationwide hospital discharge and vaccine data, we analysed all 1612 cases of myocarditis and 1613 cases of pericarditis that occurred in France in the period from May 12, 2021 to October 31, 2021. We perform matched case-control studies and find increased risks of myocarditis and pericarditis during the first week following vaccination, and particularly after the second dose, with adjusted odds ratios of myocarditis of 8.1 (95% confidence interval [CI], 6.7 to 9.9) for the BNT162b2 and 30 (95% CI, 21 to 43) for the mRNA-1273 vaccine. The largest associations are observed for myocarditis following mRNA-1273 vaccination in persons aged 18 to 24 years. Estimates of excess cases attributable to vaccination also reveal a substantial burden of both myocarditis and pericarditis across other age groups and in both males and females.