Sunburn is caused by exposure to UV radiation from the sun, which causes inflammation of the skin. While sun provides vitamin D, overexposure can lead to skin cancer later in life. UVB rays are more damaging to skin and contribute more to skin cancer and premature aging compared to UVA rays. Tanning beds emit both UVA and UVB. It is important to protect skin from overexposure to the sun through hats and sunscreen to avoid health risks like skin cancer from sunburn.