Sunburn occurs when the skin is exposed to the sun’s ultraviolet (UV) rays. These rays can damage the skin cells and cause inflammation, redness, and pain.