Scientists can recognize more than 30 different skin colors, from almost black to pinkish white. Sunlight brought about this diversity.
Long ago, our human ancestors lived in Africa and had various shades of dark skin. Dark skin is best at protecting against sunburn in the tropical heat. It also helps protect against skin cancer, which is dangerous changes in skin cells usually caused by too much exposure to ultraviolet light.
Then, about 100,000 years ago, people fanned out to other continents. In places with little sunlight, lighter skin color evolved, because dark skin was no longer necessary to protect against ultraviolet light. Light skin lets more sunlight through. This allows more production of vitamin D, which we need for calcium absorption and bone growth.