Considering the influence of dietary factors on inflammatory markers that may affect the disease course in patients with ulcerative colitis (UC), this study aimed to assess the association between dietary inflammatory index (DII) score and disease activity in patients with ulcerative colitis. This cross-sectional study included 158 patients with UC. The Mayo Clinic score was used to determine the disease severity. A food frequency questionnaire was applied to gather the dietary information, then the Shivappa et al. method was used for the calculation of DII. An association between disease severity (dependent factor) and DII score quartiles (independent factors) was conducted by a logistic regression adjusted to different covariates. In this study, 53.8% of participants were in remission or had mild disease activity. The mean DII score was − 0.24 ± 0.66. The mean DII score was significantly lower in patients with remission (-0.34 ± 0.71) compared with patients who were in the active phase (-0.1 ± 0.57) of UC (P = 0.02). The results of the logistic regression analysis showed that after adjusting for confounding factors, the odds of severe disease were 3.33 times higher among patients who had a more pro-inflammatory diet compared with patients who had an anti-inflammatory diet [OR: 3.33 (95%CI: 1.13, 9.76), p = 0.02]. In conclusion, there was a significant association between higher intake of a pro-inflammatory diet and UC severity. So, from a clinical point of view, there is a need to apply an anti-inflammatory diet to decrease disease severity in patients with ulcerative colitis.