There is a misconception about chameleons that they do this to camouflage themselves against a background. In fact, chameleons mostly change color to regulate their temperatures or to signal their intentions to other chameleons. So how do they change colors?
The outermost layer of the chameleon’s skin is transparent. Beneath this are several more layers of skin that contain specialized cells called chromatophores. The chromatophores at each level are filled with sacs of different kinds of pigment.
Normally, the pigments are locked away inside tiny sacs within the cells. But when a chameleon experiences changes in body temperature or mood, its nervous system tells specific chromatophores to expand or contract. This changes the color of the cell. By varying the activity of the different chromatophores in all the layers of the skin, the chameleon can produce a whole variety of colors and patterns.