When looking at pictures of animals in the wild, one may ask the question: Why are most of these animals brown or black, and why do we see very few colorful creatures? This question can be approached from multiple angles. I will ignore selective pressures that provide an advantage to certain colors. Instead, I will focus on the mechanism behind these colors.
Let’s begin with mammals. When we talk about most creatures being brown or black, we are usually considering mammals, since colors are vibrant across other classes (e.g. reptilia, amphibia, aves). Colors in skin and fur arise from two pigments. They generate two colors: brown-black (through melanin) and reddish-yellow. I challenge you to use this color palette to make the color green. There are evolutionary advantages to being brown. Early mammals were presumably small, rat-like creatures living on land. It was best to blend into the environment and to invest energy into escape mechanisms. Amphibians, on the other hand, were not limited to the brown dirt of land and were able to develop a green color. This does not answer why they could do this, so let me delve into that.
This is where it gets interesting.
It turns out that birds, amphibians, and reptiles are unable to generate pigments for green (and many cannot generate blue). Most of the tetrapod (four-legged) world is like this. How, then, could they possibly look so vibrant? The colors arise not from the colors of pigment, but from a molecular refraction mechanism. All of these colors arise from two pigments: black and yellow-red. Thus, when a chameleon changes color, it is not depositing pigments. Instead, it is changing the shape of its refractory cells in order to alter the refraction effect.
In bird feathers, the mechanism is a bit more complicated, but it is the same idea. If you have time, try this experiment: Take some flour, and mix it with water. Mix until the flour is suspended evenly in the water. Now, move the glass to a well-light area. What color do you see? You will notice that the suspension looks bluish-white as opposed to just white. This is due to light scattering. Shorter-wavelength blue light is more easily scattered than longer-wavelength red light. What you then witness is this scattered blue light, giving the suspension a blue tint. Another example is found in compact discs. If you stare at the bottom, you will see not just a silver-coated disc, but an array of colors reflected off the CD’s surface. This is due to the same effect, but we are now looking at scattering from tracks on the CD. Spacing of ridges and orientation of pigment granules in bird feathers generates the same effect. Though the pigments are still black and yellow-red, this scattering provides vibrant colors. If you want to learn more about this, I recommend reading this article on peacock feather coloration.
The aforementioned scattering is known at the Tyndall effect. Simply put, when a suspension of particles is exposed to light, some of this light is scattered and produces interesting colors. The flour/water example I provided was just one. You will also see a blue tint of smoke from the exhaust from some automobiles, also due to a suspension similar to our flour and water. Simply put, longer wavelengths (e.g. reds) are transmitted, but shorter wavelengths (e.g. blues) are reflected. I should note that this is a different mechanism from light scattering seen in the sky at sunset. Whereas scattering in our atmosphere is usually by very small particles (Rayleigh scattering), scattering in colloidal suspensions is by relatively larger particles (Mie scattering). This is important to note because the effects of scattering from larger particles are more vibrant and less subtle.
Mammals are not completely brown and black. An exception to the boring colors of mammals arises in the irises of our eyes. The iris is still composed of melanin, as before. However, the density of melanin determines how opaque or translucent the upper layer of the iris becomes. When more translucent, light can pass through this upper layer and be backscattered by layers below. As before, shorter wavelengths of light are more likely to be scattered. This, in turn, results in blue irises.
Like the example above, many questions in this world are nuanced, and these nuances make the questions (and answers) more interesting.