The wing patterns of butterflies and moths (Lepidoptera) are diverse and striking examples of evolutionary diversification by natural selection. Lepidopteran wing colour patterns are a key innovation, consisting of arrays of coloured scales. We still lack a general understanding of how these patterns are controlled and whether this control shows any commonality across the 160,000 moth and 17,000 butterfly species. Here, we use fine-scale mapping with population genomics and gene expression analyses to identify a gene, cortex, that regulates pattern switches in multiple species across the mimetic radiation in Heliconius butterflies. cortex belongs to a fast-evolving subfamily of the otherwise highly conserved fizzy family of cell-cycle regulators, suggesting that it probably regulates pigmentation patterning by regulating scale cell development. In parallel with findings in the peppered moth (Biston betularia), our results suggest that this mechanism is common within Lepidoptera and that cortex has become a major target for natural selection acting on colour and pattern variation in this group of insects.