The primary ingredient of sunscreen is Titanium Dioxide. This and other chemicals in the lotion absorb and reflect the UV in sunlight so it doesn’t get through to your skin.
Here’s a fun fact: as well as fusing hydrogen to helium in the core, stars do a lot of chemical reactions in their upper atmospheres. Some stars have a lot of titanium and oxygen in them so actually make their own titanium-dioxide sunscreen: a Sun protecting itself from its own UV rays! 😎