Background: The role of environmental exposures in the pathogenesis of ankylosing spondylitis (AS) remains unclear. In particular, two types of exposures have been suspected to play a role: mechanical stress and infections. The objective of this case-control study was to determine if childhood infections are associated with later development of AS. Methods: The cases with AS were identified through the Swedish national outpatient specialised-care register, based on having been given at least one AS diagnosis in the register between 2001 and 2010. Five controls per case were identified in the Swedish population register, matched at the time-point of the index case's first spondyloarthritis diagnosis on sex, birth year, and county. All cases/controls matched prior to the age of 17 years were excluded, as well as all cases/controls given a diagnosis of reactive arthritis or juvenile arthritis at any time point, or any other diagnosis of a rheumatic disease, psoriasis, iridocyclitis, or inflammatory bowel disease before the time-point of matching. All events of hospitalisation with an infection before the age of 17 years were retrieved from the register, and categorised according to the focus of the infection. Odds ratios (ORs) and confidence intervals (CIs) were determined through conditional logistic regression analyses. Results: Of the 2453 cases with AS and 10,257 controls, 17.4 % of the cases and 16.3 % of the controls had been hospitalised with an infection before the age of 17 years (OR 1.08, 95 % CI 0.96-1.22). Appendicitis (1.5 % cases; 2.5 % controls; OR 0.59, 95 % CI 0.41-0.83), respiratory tract infections (cases 11.2 %; controls 9.2 %; OR 1.24, 95 % CI 1.07-1.44) and, in particular, tonsillitis (cases 3.7 %; controls 2.8 %; OR 1.31, 95 % CI 1.03-1.67) were associated with AS. There were no associations between AS and any other type of infection, and the point estimates were similar in several sensitivity analyses. Conclusions: Childhood appendicitis was associated with a decreased risk, whereas respiratory tract infections were associated with an increased risk for later development of AS. These findings support a possible relationship between childhood infections and later development of AS, although the study is limited to infections resulting in inpatient care.