Chameleons change colour in order to blend in with their surroundings. This makes it more difficult for their enemies- or their prey- to see them.
Chameleons have a transparent outer skin, with several skin layers underneath it that contain special cells called chromatophores. These chromatophores contain sacks of colour pigments that can contract and expand in response to internal signals. For example, if a chameleon became excited, it turns red by causing the red cells to fully expand, blocking out the other colours that are underneath the skin. Once it has calmed down, it becomes green again by allowing the red cells to contract.
Chameleons can expand and contract their colour cells such a way as to create a whole variety of colours and patterns. Light, temperature, and its emotional state can also bring about a chameleon’s change in colour. The chameleon will most often change between green, brown and gray, which coincidentally, often match the background colors of their habitat.