Ultraviolet light lies outside the visible spectrum (at frequencies higher than violet - hence its name) and so cannot be seen with the human eye. The sun emits a great deal of this light, and due to its short wavelength, the photons of UV light carry a great deal of energy. This energy, combined with the UV-B (higher frequency UV) part of the spectrum's ability to penetrate quite deep into the skin before being absorbed, causes the heating and damage that leads to skin cancer and sunburn (and, in part, to tattoo fade).
The ozone layer absorbs a significant part of the UV light that reaches the earth, although more than enough makes it thorugh to do a great deal of damage to your skin over time. And, the amount getting through generally increases as the ozone layer becomes more and more unstable.
Fortunately for life, most substances absorb UV - the high energies of ultraviolet light correspond to transitions to very high quantum numbers in the absorbing electron clouds, where there are very many close together states for the light to be absorbed into. The problem is, when you're out in the sun, after the tenous protective layer of ozone, there is not much between the UV and you except the thin atmosphere (although the atmosphere does a very good job scattering bluelight - giving the sky its blue color)! Sunscreen and glass both protect you from UV light by providing a dense layer of absorbers that filter most of the UV light from the sunlight and reradiate the energy as lower energy light or heat.
Glass is generally more protective than sunscreen as it normally forms a much thicker layer of absorbing material. As mentioned above, glass is not so much unique in that it stops UV - the brick wall around the window does that much more thoroughly, rather it is unique that it lets most of the visible spectrum through.
Different types of glass do tend to let through varying amounts of the lower energy UV-A light (as it is right on the edge of the visible spectrum), but this is believed to be less damaging. However, when purchasing sunglasses, it is wise to look for a UV protection factor as it is believed that even UV-A can damage the sensitive cells in your eyes.