Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use WebP images on website [duplicate]

Tags:

css

image

webp

I want try to use images in WebP format as background images on my webpages. But I'm not sure, how make condition in CSS that if browser not support WebP format so in this case use classic jpg image. I find this example code, bud it doesn't work

.mybackgroundimage {
    background-image: url("image.jpg");
    background-image: image("image.webp" format('webp'), "image.jpg");
}
like image 526
Petr Šrámek Avatar asked Apr 27 '13 10:04

Petr Šrámek


1 Answers

You must use modernizr to detect whether browser support webp or not and then apply appropriate style to it

.no-webp .mybackgroundimage 
{
background: url('image.jpg') no-repeat;

}

.webp .mybackgroundimage
{
background: url('image.webp') no-repeat;

}
like image 68
Soheil Ghahremani Avatar answered Oct 01 '22 00:10

Soheil Ghahremani