Tanning is mostly caused by the skin's exposure to ultraviolet (UV) light from the sun. It stimulates melanin formation, a substance that darkens the skin and protects it from further injury.