I would like to use the WebP image format in my CSS background-image
property. But, since WebP is quite new and still not supported by all browsers new and old, I would also like to add support for a JPEG version of that image as a fallback.
I know I can use the <picture>
tag to do this like:
<picture>
<source type="image/webp" srcset="image.webp">
<source type="image/jpeg" srcset="image.jpg">
<img src="image.jpg">
</picture>
And this would make the browser load the first supported format. But can I achieve the same effect somehow using only CSS, since I am setting a background image using the background-image
property? I know I can select images based on screen size using @media
queries, but how do I load images based on browser support?
I have tried to search for a solution, but could not find one. Let me know if this is a duplicate and the solution already exists.
Thanks.