I agree with the previous answer: tanning itself is a protective reaction of the body to UV radiation. But thanks to UV radiation, vitamin D is synthesized in our body.
Synthesis of vitamin D in the body: the precursor of cholecalciferol - previtamin D3 is formed in the epidermis of the skin under the influence of ultraviolet rays of sunlight from provitamin D3. Previtamin D3 is converted to cholecalciferol by thermal isomerization (at body temperature). In the epidermis, cholecalciferol binds to vitamin D-binding protein and in this form enters the bloodstream and is transferred to the liver. Shade and cloudy weather can reduce previtamin synthesis by 60%. The sunlight necessary for the synthesis of previtamin does not penetrate glass, clothing and sunscreen. A sufficient amount of the vitamin is produced by the skin with regular irradiation in a tanning bed, but this can lead to skin cancer.
To ensure a normal dose of the vitamin, you need to be with your limbs exposed to the sun in the midday sun (from 10 am to 3 hours of the day) at least twice a week. For people with fair skin, a 5-minute sunbath is enough, dark-skinned people should be in the sun for at least half an hour.
Vitamin D deficiency plays a major role in the development of rickets in children. Long-term vitamin D deficiency can lead to an increased incidence of cancer, increasing the likelihood of developing osteoporosis. Recently, the results of studies have been published linking vitamin deficiency with a weakened immune system, an increased risk of developing cardiovascular diseases.
Sunburn is the adaptation of our body to increase the intensity of light. The thing is that the sun's rays, in addition to light in the visible range, also carry high-energy ultraviolet radiation that can harm the genetic material of the cell. To protect against it, the body produces a black pigment, melanin, which absorbs light not only in the visible spectrum (which is why it is black), but also in the UV part, thus shielding chromosomes from destruction. In the cold season, the intensity of radiation decreases and the body does not need to spend substances (in particular the amino acid tyrosine) and energy for melanin synthesis, but in summer this function is vital. There are people who have impaired function of melanin synthesis in the skin, the so-called albinos. For them, being in direct sunlight is fraught with serious problems up to melanoma (malignant transformation of epidermal cells)