Self-tanners are touted as a safe alternative to tanning beds or sun exposure, which is true for the most part. These products can achieve a warm, sun-kissed glow without soaking in UVA and UVB rays for hours on end, but they aren't magically causing the body to produce more melanin like one might think.
Unlike traditional UVA/B tanning, self-tanners use a coloring agent called dihydroxyacetone or DHA to stain the skin. When applied topically, DHA reacts to the skin's amino acids to produce melanoidins, which are brown polymer pigments. These pigments sit on the outermost layer of skin, creating the appearance of a tan without actually increasing melanin (via the American Journal of Clinical Dermatology).
Think of a self-tanner like hair dye. A brunette can dye their hair blonde, but when their roots grow back, they'll still be brunette. Similarly, a person with lighter skin can use self-tanner to stain their skin to be a darker shade, but when these outermost dead skin cells naturally wear off, and new cells are produced, their melanin levels — and ability to avoid sun damage — remain the same.