In the skin, melanin functions as an absorptive pigment. A pigment is a substance that, as a result of selective colour (wavelength) absorption, determines the colours of many plants and animals. In humans, the two types of melanin present in the skin (eumelanin and pheomelanin) are responsible for different skin tone (which is induced by ultraviolet radiation), and the constituent of freckles.
Eumelanin is a black or brown pigment, and is mainly concerned with the protection of the skin by absorbing incoming UV radiation. This protective ability warrants melanin to be termed a photoprotectant (a substance capable of providing protection against radiation from the sun). Pheomelanin is a reddish pigment, a very weak absorptive of UV radiation, further it also acts as a photosensitizer (makes your skin sensitive to light), where it increases sun sensitivity and skin ageing. (Source)