What image-set() does
image-set() has existed in Chromium browsers since 2012 and in Safari since version 6; Firefox only picked it up in version 88. It works as the CSS background counterpart to the HTML srcset attribute, letting you hand the browser several candidate images and leaving the choice to it. The property values that accept it are content, cursor and, most practically, background-image.
The CSS specification frames the problem in terms of resolution matching, but also connection quality: an ideal image matches the display's resolution, yet a user on a slow mobile link may be better served by a smaller image than by a sharp one that takes ages to arrive.
Resolution selection syntax
.hero {
background-image: image-set("platypus.png" 1x, "platypus-2x.png" 2x);
}
The 1x descriptor marks the low-resolution file and 2x the high-resolution one. The x unit is an alias for dppx, or dots per pixel unit.
Prefix requirements differ by engine. Chromium-based browsers (Chrome, Edge, Opera, Samsung Internet) still need -webkit-, which Autoprefixer adds for you. Safari dropped the prefix but relies on an older syntax in which the path must be wrapped in url(). A plain background-image: url() can sit alongside as a fallback for browsers without image-set support.
.hero {
/* Fallback */
background-image: url("platypus.png");
/* Chrome/Edge/Opera/Samsung, Safari will fallback to this as well */
background-image: -webkit-image-set(url("platypus.png") 1x, url("platypus-2x.png") 2x);
/* Standard use */
background-image: image-set("platypus.png" 1x, "platypus-2x.png" 2x);
}
Sharp displays then receive the detailed asset, while slow connections and low-density screens cause the browser to request the smaller file on its own. If you need to force the high-res image onto high-res devices regardless of connection speed, the min-resolution media query is the alternative to image-set.
Next-gen formats and the type descriptor
Safari 14 brought WebP support, making the format usable in every modern browser except Internet Explorer. WebP typically produces files smaller than JPG, PNG or GIF at equivalent quality. Newer options are arriving: AVIF is remarkably small, already shipped in Chrome, Opera and Samsung Internet, and present behind a flag in Firefox. Design tooling for AVIF is still sparse, though the Chrome team's Squoosh app converts images to it. WebP 2, HEIF and JPEG XL may reach browsers later.
HTML has handled this problem through <picture> for years:
<picture>
<source type="image/avif">
<img src="./kitten.jpg" alt="a small kitten">
</picture>
image-set() offers the CSS equivalent by accepting a MIME type for each candidate. Be aware that this particular feature is currently supported only in Firefox 89.
.div1 {
background-image: image-set(
"kitten.avif" type("image/avif"),
"kitten.jpg" type("image/jpeg")
);
}
Order matters only as a convention here: the modern format comes first and the fallback second, and exactly one file is downloaded. A browser without AVIF support skips the first entry and fetches the fallback; one with AVIF support never touches the fallback. The fallback can be any widely supported type — here is the same pattern with a PNG:
.div2 {
background-image: image-set(
"puppy.webp" type("image/webp"),
"puppy.png" type("image/png")
);
}
Chromium and Safari do not yet understand type. In those engines image-set() is usable today only for supplying multiple resolutions of broadly supported formats, not for adding legacy fallbacks to WebP or AVIF. Combining both axes — resolutions and formats — is technically expressible if you want it:
.div2 {
background-image: image-set(
"puppy.webp" type("image/webp") 1x,
"puppy2x.webp" type("image/webp") 2x,
"puppy.png" type("image/png") 1x,
"puppy2x.png" type("image/png") 2x
);
}
When a background isn't required
If your only reason for reaching for background-image is modern format support, <picture> may be the better route given its wider support. Placing the image with position: absolute makes it straightforward to layer other elements on top, and CSS grid offers a second easy way to overlap HTML elements without absolute positioning.



