1. Although it is well established that the deposition of melanin pigment in the cuticle of larval Lepidoptera is influenced by both environmental and genetic factors, few studies have examined intra-individual regional variation in the degree of melanism or the ontogenetic dynamics of this trait. Here, heritable and density-dependent effects on within-individual and stage-specific variation in melanism were examined in caterpillars of the Egyptian cotton leafworm, Spodoptera littoralis (Boisduval). 2. Using quantitative spectrometric methods, it is shown that cuticular melanism changes dramatically within larval stadia, showing the highest and lowest levels of melanism early (first day) and late (final day) in each larval stadium respectively. However, solitary-reared caterpillars were significantly paler than those reared gregariously at all stages of development and maintained greater levels of variation in melanism. This variation in melanism was repeatable and exhibited a significant heritable component (narrow sense heritability based on offspring–parent regressions: h2 = 0.18–0.30). 3. The degree of melanism was correlated negatively with larval body weight in solitary caterpillars, but not gregarious ones. Melanism also varied spatially, with the lateral longitudinal band being consistently darker than the dorsal or dorso-lateral bands. Crowd-rearing increased melanism in all regions of larval cuticle, but the extent of crowding-induced melanism was more pronounced in the dorsal and dorso-lateral bands than in the lateral one. 4. These results indicate that although cuticular melanism is a highly dynamic trait, ontogenetic changes in relative cuticular melanism are both predictable and repeatable within individuals and genotypes. This has implications for our understanding of the evolution of melanism and for applying artificial selection on the basis of colour.