What causes different skin colours?
Yes, melanin is the primary pigment responsible for differing skin color, including tanning. It does provide protection against ultraviolet radiation. See the human skin color map in the reference. The darkest skin is found in the equatorial regions with the highest incident ultraviolet radiation. Skin is lighter at higher latitudes, for two reasons. Less protection is needed against ultraviolet radiation. Further, you don’t want melanin interfering with the absorbtion of UV, since that is the primary source of vitamin D3 for the body.