The habitat associations of individuals underpin the dynamics of species distributions. Broad-scale gradients in climate can alter habitat associations across species’ geographic ranges, but topographic heterogeneity creates local microclimates which could generate variation in habitat use at finer spatial scales. We examined the selection of microhabitats for egg-laying by populations of a thermally-constrained butterfly, the skipper Hesperia comma, across 16 sites with different regional temperatures and topographic microclimates. Using models of thermal microclimate, we examined how the association between eggs and warm bare ground microhabitats varied with ambient temperature, and predicted bare ground associations in 287 existing H. comma populations, to investigate the relative impacts of regional temperatures and topographic microclimates on microhabitat use. Eggs were most strongly associated with bare ground in relatively cool sites, indicating climate-driven changes in microhabitat use. The majority of temperature variation between study sites was attributable to topographic microclimates rather than regional temperature differences, such that changes in microhabitat associations occurred principally between north- and south-facing slopes within the same region. Predicted microhabitat associations across the UK distribution of H. comma showed that, due to the large temperature differences generated by topography, most of the between-population variation in microhabitat use occurs locally within 5 km grid squares, with a smaller proportion occurring at a regional level between 5 km squares. Our findings show how microclimatic variation generated by topography alters the habitat associations of populations at fine spatial scales, suggesting that microclimate-driven changes in habitat suitability could shape species’ distribution dynamics and their responses to environmental change.