Melanin granules are the one that responsible for the dark color of the skin. The melanin granules can absorb light radiation from sunlight like (UV A or UV B). This will protect the skin from the radiation so it will prevent damage to the skin, which was can result into the skin cell become cancer.
Since melanin granules located in the epidermis, it can protect basal cell of epidermis that constantly doing cell division and dermis layer. The granules also not easily got shed because it was in the deep layer of epidermis, not in the outer layer.