It is a common misconception that chameleons change colors for disguise, to camouflage themselves and blend in with the environment. Chameleons, in reality, change color to either regulate their temperature or communicate. They can absorb more heat from the sun or reflect it by making their skin color darker or lighter. They also change colors to communicate information to other chameleons and even people.
The color of the chameleon is a reflection of its intent and mood. For example, a bright red chameleon is possibly upset, threatened or excited. Chameleons are able to change their colors thanks to layers of skin that contain cells with different pigments. The mood or body temperature of the chameleon causes these cells to contract or expand, changing the color of the chameleon. Chameleons can achieve a wide range of colors this way.
More about chameleons:
Some other sites say that chameleons change color also for camouflage. So is this not true at all?
Moderator's reply: In the past, it was generally believed that chameleons change color for camouflage. However, recent studies have revealed that a chameleon changes colors for communication, to show their present mood and intent to others. Some of it is based on studies that show that standing out in terms of color from the environment is more advantageous in mating in terms of evolution (see for ex, 2008 study on the evolution of chameleon color change published in PLOS Biology Journal).
Studies are still ongoing about this but the consensus among scientists as of 2013 is that chameleons change color mostly for communication purposes.