Researchers from the University of Southampton found that instead of using a single gene to control pigment production, corals use multiple copies of the same gene.
Depending on how many genes are active, the corals will become more or less colourful, researchers said.
"It was one of the longstanding mysteries of coral reef biology - why sometimes individuals of the same coral species can show such dramatic differences in their colour, despite sitting side-by-side on the reef and being exposed to the same environmental conditions," said Dr Jorg Wiedenmann, Professor of Biological Oceanography and Head of the University's Coral Reef Laboratory.
The research, published in the journal Molecular Ecology, also explained how this strategy could help corals to survive in stressful environments.
More From This Section
Using the staghorn coral Acropora millepora as a model, the team found that the fluorescent pigments that are mostly responsible for coral colours act as sunscreens for the symbiotic algae that live in the coral tissue.
These alga require light to produce sugars, which they can contribute to the nutrition of the corals in return for the shelter and the supply of nutrients that are provided by the coral host.
This light stress can contribute to the loss of the symbiotic algae, a process known as coral bleaching. If the partnership cannot be re-established, the corals often die.
"Corals are firmly attached to the substrate, so they can't just move in the shade when they receive too much sunlight," Wiedenmann said.
"Instead, they need to boost their capacity to cope with too much sun during these times. We show that increased light levels switch the genes on that are responsible for the production of the colourful sunscreening pigments.
However, the enhanced protection comes at a cost and the corals need to allocate substantial energy reserves to accumulate the high amounts of protein pigments that are characteristically found in brightly coloured corals.
This energy might be divided away from other important processes, potentially resulting in reduced growth rates or lower numbers of offspring.
Therefore, being brightly colour might not be a good investment for corals settling in less light exposed parts of the reefs, researchers said.