image-set() CSS Function
The image-set() function offers several versions of an image, such as 1x and 2x or different formats, so the browser can pick the best one.
Description
The image-set() CSS function lets you offer several versions of an image and have the browser choose the most suitable one. It is the CSS equivalent of the srcset attribute on the HTML img element. Each option is an image followed by a resolution, such as 1x or 2x, and optionally a file type. The browser picks the image that best matches the screen's pixel density and the formats it supports, so high-density screens get sharp images while other devices avoid downloading unnecessarily large files.
Resolutions are written with the x unit (an alias of dppx), or with dpi or dpcm. The type() function can be added to an option to name its MIME type, for example type("image/avif"); browsers skip options whose type they cannot decode, which makes it easy to serve modern formats with a fallback. Options are not limited to URLs: any <image> value, including gradients, can be used.
/* Sharper background on high-density screens */
.hero {
background-image: url("hero.jpg"); /* fallback */
background-image: image-set(
"hero.jpg" 1x,
"hero@2x.jpg" 2x
);
}
/* Prefer AVIF, then WebP, then JPEG */
.banner {
background-image: image-set(
"banner.avif" type("image/avif"),
"banner.webp" type("image/webp"),
"banner.jpg" type("image/jpeg")
);
}
image-set() can be used anywhere an image is accepted, such as background-image, mask-image, border-image and the content property.
Interactive Demo
Syntax
image-set() = image-set( <image-set-option># )
<image-set-option> = [ <image> | <string> ] [ <resolution> || type(<string>) ]?
Values
- <image> | <string>The image to use. A <string> is treated as a URL. Any <image> value is allowed, including url() and gradients.
- <resolution>Optional. The pixel density the image is intended for, such as 1x, 2x, 192dpi or 2dppx. Defaults to 1x.
- type(<string>)Optional. The MIME type of the image, such as "image/webp". Options with unsupported types are skipped.
Example
Browser Support
The following information will show you the current browser support for the CSS image-set() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





