Temperature is widely regarded as a major driver of species richness, but the mechanisms are debated. Niche theory suggests temperature may affect richness by filtering traits and species in colder habitats while promoting specialization in warmer ones. However, tests of this theory are rare because niche dimensions are challenging to quantify along broad thermal gradients. Here, we use individual-level trait data from a long-term monitoring network spanning a large geographic extent to test niche-based theory of community assembly in small mammals. We examined variation in body size among 23 communities of North American rodents sampled across the National Ecological Observatory Network (NEON), ranging from northern hardwood forests to subtropical deserts. We quantified body size similarity among species using a metric of overlap that accounts for individual variation, and fit a structural equation model to disentangle the relationships between temperature, productivity, body size overlap, and species richness. We document a latitudinal gradient of declining similarity in body size among species towards the tropics and overall increase in the dimensions of community-wide trait space in warmer habitats. Neither environmental temperature nor net primary productivity directly affect rodent species richness. Instead, temperature determines the community-wide niche space that species can occupy, which in turn alters richness. We suggest a latitudinal gradient of trait space expansion towards the tropics may be widespread and underlie gradients in species diversity.