Created
May 29, 2021 22:56
-
-
Save dmpinder/4218cda18c2ac085324365b6c0ace5c8 to your computer and use it in GitHub Desktop.
WebP mixin for SASS with @supports detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin webp($webp, $fallback) { | |
background: url($fallback); | |
/* Chrome 66+, Edge 79+, Opera 53+, Android Brower 80+ */ | |
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution:.001dpcm) { | |
@supports (background-image: -webkit-image-set(url($webp) 1x)) { | |
background: -webkit-image-set(url($webp) 1x); | |
} | |
} | |
/* FF 66+ */ | |
@supports (flex-basis: max-content) and (-moz-appearance: meterbar) { | |
background: url($webp); | |
} | |
} | |
// Usage | |
@include webp('hero.webp', 'hero.jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment