The ultraviolet rays in sunlight bleach the hair and destroy the melanin in it, oxidizing the melanin into a colorless compound. Melanin is a pigment found in humans' hair and skin that gives each its color. Because hair is already dead, it cannot produce more melanin to replace the destroyed melanin molecules. The hair stays the lighter color until new hair grows in.
Although exposure to the sun lightens hair, exposure to sunlight darkens skin. Skin gets darker because the damage from the ultraviolet rays in sunlight triggers the production of more melanin in a person's skin to help fight off and minimize the effects of the harmful rays. This reaction of skin, slower than the bleaching of hair, is a process called "melanogenesis," in which the skin cells ramp up the overall production of melanin pigment. This process causes a person's skin to tan due to the higher levels of melanin in the skin. The melanin in skin and hair is meant to protect the other tissues from ultraviolet light, which can damage DNA and cause cancer. The exact mechanism by which the ultraviolet rays break down the melanin molecules in hair to simpler, less colorful compounds is not entirely clear.