Inflammation plays a pivotal in the occurrence and development of coronary heart disease (CHD). We aim to investigate the association between the Dietary Inflammatory Index (DII) and CHD in the present study. In this cross-sectional study, adult participants from the National Health and Nutrition Examination Survey (NHANES) (1999–2018) were enrolled. The social demographic information, lifestyle factors, blood biochemical measurements, dietary information, and CHD status of all the participants were systematically collected. Multivariable logistic regression was adopted to investigate the association between the risk of CHD and the DII. Besides, restricted cubic spline (RCS) analysis was used to explore whether there was a nonlinear association of the DII and CHD. Subgroup analysis stratified by sex, age, race/ethnicity, and BMI was conducted to evaluate the association of the DII and CHD among different populations. A total of 45,306 adults from NHANES (1999–2018) were included. Compared with individuals without CHD, the DIIs of the participants with CHD were significantly elevated. A positive association was observed between the DII and CHD in multivariable logistic analysis after adjusting for age, sex, race/ethnicity, education levels, smoking, drinking, diabetes, hypertension, and body mass index (BMI). Results of RCS analysis suggested a nonlinear relationship between the DII and CHD. In addition, the increment of the DII had a greater impact on female individuals compared with male individuals. The DII is closely associated with the risk of CHD. For better prevention and treatment of CHD, more attention should be paid to controlling dietary inflammation.