AbstractAimThere is little consensus about the relative roles of biotic versus abiotic factors in setting limits to species distributions or in generating geographical patterns of species richness. However, despite the probable importance of host availability in governing the distribution and diversity of consumers, few studies have simultaneously tested the effects of resource distribution and diversity on consumer ranges and richness patterns.LocationSierra de Guadarrama, central Spain.MethodsWe examined the effects of biotic resources, consumer attributes and climate on the ranges and species richness patterns of 43 specialist butterflies at 40 sites over a 1800‐m elevational gradient. Evidence for resource use was based on comprehensive field records of oviposition and larval feeding on host plants.ResultsWe show that limitation by either biotic interactions with resources (the distributions and parts eaten of the larval host plants) or intrinsic dispersal ability was stronger at upper than lower elevational range limits for butterflies. Both resource and consumer richness followed a unimodal, humped pattern over the elevational gradient, but host plant richness peaked 300 m lower than butterfly richness. In addition, whereas changes in butterfly species richness were roughly symmetrical around peak richness over the gradient studied, the host plants showed markedly lower species richness at high elevations (> 1750 m). Butterfly species richness increased with host plant resource diversity and relative humidity, with a steeper response to host plant richness in cooler sites (at higher elevations).Main conclusionsThe results demonstrate the role of bottom‐up control by resource availability in limiting consumer distributions and richness. Importantly, resource limitation had increasing relevance towards the coolest parts of environmental gradients and those poorest in resource species, with potential consequences for ecological responses to environmental change.