To explore the relationship between proinflammatory diet, habitual salt intake and the onset of type 2 diabetes. This prospective study was conducted among 171 094 UK Biobank participants who completed at least one 24-h dietary questionnaire and were free of diabetes at baseline. Participants were followed up until 1 March 2023 for type 2 diabetes incidence, with diagnosis information obtained from linked medical records. An Energy-adjusted Diet Inflammatory Index (E-DII) was calculated based on 28 food parameters. Habitual salt intake was determined through the self-reported frequency of adding salt to foods. The associations between E-DII, habitual salt intake and type 2 diabetes incidence were tested by the Cox proportional hazard regression model. Over a median follow-up period of 13.5 years, 6216 cases of type 2 diabetes were documented. Compared with participants with a low E-DII (indicative of an anti-inflammatory diet), participants with a high E-DII (indicative of a proinflammatory diet) had an 18% heightened risk of developing type 2 diabetes. The association between E-DII and type 2 diabetes tends to be linear after adjustment for major confounders. Participants with a proinflammatory diet and always adding salt to foods had the highest risk of type 2 diabetes incidence (hazard ratio 1.60, 95% confidence interval 1.32-1.94). Our findings indicate that a proinflammatory diet and higher habitual salt intake were associated with an increased risk of type 2 diabetes. These results support the public health promotion of an anti-inflammatory diet and reducing salt intake to prevent the onset of type 2 diabetes.