Melanin is a broad term for a group of natural pigments found in most organisms produced by the oxidation of the amino acid tyrosine, followed by polymerization.
Most recent scientific evidence indicates that all humans originated in Africa, then populated the rest of the world through successive radiations. It seems likely that the first modern humans had darker skin as with the indigenous people of Africa today. As some of these original peoples migrated and settled in areas of Asia and Europe, the selective pressure for Melanin production decreased in climates where radiation from the sun was less intense.
As with peoples having migrated northward, those with light skin migrating toward the equator acclimatize to the much stronger solar radiation. Most people’s skin darkens when exposed to UV light, giving them more protection when it is needed. This is the physiological purpose of sun tanning. Dark-skinned people, who produce more skin-protecting Melanin, have a greater protection against sunburn and the development of melanoma, a potentially deadly form of skin cancer, as well as other health problems related to exposure to strong solar radiation.
(Compiled by using various sources including Wikipedia)