By producing melanin (pigment), the skin protects the underlying structures from ultraviolet light's harmful rays while producing vitamin D, which works with calcium for multiple body processes.
Vitamin D is produced by the skin when it is exposed to the sunlight. Ultraviolet B (UVB) is the part of the sun's rays that affects the skin to produce such vitamin.