I am trying to use webp images throughout my site due to the better compression. However I am aware that safari does not support webp. The images are loaded using background-image: url("img/img.webp)
. I then apply other background
properties.
I understand the <picture>
tag can be used to show different images depending on browser support. Like so.
<picture>
<source srcset="some_img.webp" type="image/webp">
<img src="some_img.jpg"alt="">
</picture>
However it would be much more convenient if there was a way to do it using css to save me having to write new html and styling for all the images.
For instance something like this
#image-id {
background-image: url("../img/img.webp", "../img/img.jpeg"); // show jpeg if webp not supported
}
Or if that is not possible then maybe something like this
@media only screen and (safari-specific-property:) {
background-image: url("../img/img.jpeg"); // show jpeg for safari
}
What is the best solution for using webp images while maintaining browser support, which ideally uses css?