How do you detect in CSS if webp images are supported?
.home-banner-background {
background-image: url('img/banner.jpg');
}
/*Here is an if statement that will check if webp is supported*/ {
.home-banner-background {
background-image: url('img/banner.webp');
}
}
Is there an "if" statement which can do that?
You can use Modernizr. It is a tool that detect available features on the user's browser. It is just a script to add in your website, and with it, you can write something like that :
.no-webp .home-banner-background {
background-image: url('img/banner.jpg');
}
.webp .home-banner-background {
background-image: url('img/banner.webp');
}