Ultraviolet radiation from the sun (UVB) has beneficial and harmful effects on human health. It is the most important environmental risk factor for the development of non-melanoma skin cancer, such as basal and squamous cell carcinomas.
The other side is that the human body's requirements for vitamin D are mainly achieved by UVB-induced photosynthesis in the skin.
Sunscreen prevents sunburn by blocking UVB light. Theoretically, sunscreen use lowers vitamin D levels. However, as a practical matter, very few people put on enough sunscreen to block all UVB light, or they use sunscreen irregularly, so sunscreen's effects on vitamin D might not be that important. An Australian study1 showed no difference in vitamin D absorption between adults randomly assigned to use sunscreen and those assigned a placebo cream.
1. Marks R, Foley P, Jolley D, Knight K, Harrison J, Thompson S. The effect of regular sunscreen use on vitamin D levels in an Australian population. Results of a randomized controlled trial. Arch Dernatology. 2015;Volume131(4):415-421.