How is sunlight both harmful and beneficial?
Sunlight provides virtually all the energy in our world. Without it, plants wouldn’t grow and we wouldn’t have food or daylight. We wouldn’t even have fossil fuels such as coal and petroleum because those were formed from vegetation that itself derived energy from the sun. However, sunlight also contains ultraviolet light, which can damage chemicals in biological tissue. Long exposure to ultraviolet light can age your skin or cause cancer.
Sunlight also provides vitamin D to us, which is known to help prevent some forms of cancer that are worse than the skin cancer you can potentially get from the sun. You do not have to stand in the sun all day to get enough vitamin D though, 10-15 mintues is plenty and you’ll avoid a sunburn that way.

