Depression is a potential risk factor for developing IBD. This association may be related to GI symptoms occurring before diagnosis. We aimed to determine whether depression, adjusted for pre-existing GI symptoms, is associated with subsequent IBD.We conducted a nested case-control study using the Clinical Practice Research Datalink identifying incident cases of UC and Crohn's disease (CD) from 1998 to 2016. Controls without IBD were matched for age and sex. We measured exposure to prevalent depression 4.5-5.5 years before IBD diagnosis. We created two sub-groups with prevalent depression based on whether individuals had reported GI symptoms before the onset of depression. We used conditional logistic regression to derive ORs for the risk of IBD depending on depression status.We identified 10 829 UC cases, 4531 CD cases and 15 360 controls. There was an excess of prevalent depression 5 years before IBD diagnosis relative to controls (UC: 3.7% vs 2.7%, CD 3.7% vs 2.9%). Individuals with GI symptoms prior to the diagnosis of depression had increased adjusted risks of developing UC and CD compared with those without depression (UC: OR 1.47, 95% CI 1.21 to 1.79; CD: OR 1.41, 95% CI 1.04 to 1.92). Individuals with depression alone had similar risks of UC and CD to those without depression (UC: OR 1.13, 95% CI 0.99 to 1.29; CD: OR 1.12, 95% CI 0.91 to 1.38).Depression, in the absence of prior GI symptoms, is not associated with subsequent development of IBD. However, depression with GI symptoms should prompt investigation for IBD.