Favorites

image-set() CSS Function

image-set()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

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.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

Demo Code
HTML Code
<div class="demo-element"></div>
CSS Code
.demo-element {
	width: 280px;
	height: 170px;
	background-color: #e7ecff;
	border: 2px solid #4361ee;
	background-size: cover;
	background-image: image-set("/css-properties/images/sunset.jpg" 1x, "/css-properties/images/sunset.jpg" 2x);
}

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

<div class="wrap">
<h1>CSS image-set() examples</h1>
<div class="grid">
<div class="card">
<div class="box">Chosen by image-set()</div>
<div class="label">image-set(gradient-a 1x, gradient-b 2x, gradient-c 3x)</div>
</div>
</div>
<p class="note legend"><span class="one"></span>1x screen &nbsp; <span class="two"></span>2x screen &nbsp; <span class="three"></span>3x screen</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* image-set() examples */
/* Gradients stand in for real images so the demo is self-contained.
The box shows which option your screen's pixel density selects. */
.box {
height: 160px;
border-radius: 12px;
display: grid;
place-items: center;
color: #fff;
font-weight: 700;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
background-image: image-set(
linear-gradient(135deg, #2563eb, #0891b2) 1x,
linear-gradient(135deg, #db2777, #f97316) 2x,
linear-gradient(135deg, #16a34a, #84cc16) 3x
);
}

.legend span {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 3px;
margin-right: 4px;
vertical-align: middle;
}

.legend .one { background: #2563eb; }
.legend .two { background: #db2777; }
.legend .three { background: #16a34a; }
Open in editor

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.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.