Objectives. To assess the relationship between infections and the risk of pediatric-onset inflammatory bowel disease (IBD). Methods. We conducted a nested case-control study of 501 incident cases aged ?17 years and 9,442 controls who were members of Kaiser Permanente Northern California for at least one consecutive year between 1996 and 2006. IBD was confirmed and the incidence date was adjudicated by pediatric gastroenterologists. Hospitalized infections were identified from the principal diagnosis code of electronic inpatient records. Medications to treat infections were identified during the hospitalization. Conditional logistic regression was used to assess the associations between hospitalized infections, medications, and Crohn’s disease and ulcerative colitis. Results. In the year prior to diagnosis, both hospitalized infection of any system (OR 6.3; 95% CI 1.6-23.9) and hospitalized intestinal infection (OR 19.4; 95% CI 2.6-143.2) were associated with CD. Hospitalized infections of any system were inversely associated with UC after excluding the year prior to diagnosis (OR 0.4; 95% CI 0.2-0.9). No UC case had a hospitalized gastrointestinal infection prior to diagnosis. Conclusion. Infections appear to play opposite roles prior to the diagnosis of CD and UC. Infections may be associated with an increased risk of CD and a decreased risk of UC.