Pigmentation is involved in a wide array of biological functions across insect 13 orders, including body patterning, thermoregulation, and immunity. The melanin pathway, in 14 particular, has been characterized in several species. However, molecular evolution of the genes 15 involved in this pathway is poorly characterized, and their roles in pigmentation of early 16 developmental stages are just beginning to be explored in non-model organisms. We traced the 17 molecular evolution of six melanin pathway genes in 53 species of Lepidoptera covering butterflies 18 and moths, and representing over 100 million years of diversification. We compared the rates of 19 synonymous and nonsynonymous substitutions within and between these genes to study signatures 20 of selection at the level of individual sites, genes, and branches of the gene tree. We found that 21 molecular evolution of all six genes was governed by strong purifying selection. Yet, a number of 22 sites showed signs of being under positive selection, including in the highly conserved domain 23 regions of three genes. Further, we traced the expression of these genes across developmental 24 stages, tissues, and sexes in the Papilio polytes butterfly using a developmental transcriptome 25 dataset. We observed that the expression patterns of the genes in P. polytes largely reflected their 26 known tissue-specific function in other species. The expression of sequentially acting genes in the 27 melanin pathway was correlated. Interestingly, four out of six melanin pathway genes (ebony, pale, 28 aaNAT, and DDC) showed a sexually dimorphic pattern of developmental heterochrony; i.e., 29 females showed peak activity much earlier in pupal development compared to that of males. Our 30 evolutionary and developmental analyses suggest that the vast diversity of wing patterning and 31 pigmentation in Lepidoptera may have been aided largely by differential developmental regulation 32 of genes in a highly conserved pathway, in which the sequence evolution of individual genes is 33 highly constrained. 34 35