image-set() CSS function

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2023.

The image-set() CSS functional notation is a method of letting the browser pick the most appropriate CSS image from a given set, primarily for high pixel density screens.

Resolution and bandwidth differ by device and network access. The image-set() function delivers the most appropriate image resolution for a user's device, providing a set of image options — each with an associated resolution declaration — from which the browser picks the most appropriate for the device and settings. Resolution can be used as a proxy for filesize — a user agent on a slow mobile connection with a high-resolution screen may prefer to receive lower-resolution images rather than waiting for a higher resolution image to load.

image-set() allows the author to provide options rather than determining what each individual user needs.

Syntax

css
/* Select image based on resolution */
image-set(
  "image1.jpg" 1x,
  "image2.jpg" 2x
);

image-set(
  url("image1.jpg") 1x,
  url("image2.jpg") 2x
);

/* Select gradient based on resolution */
image-set(
  linear-gradient(blue, white) 1x,
  linear-gradient(blue, green) 2x
);

/* Select image based on supported formats */
image-set(
  url("image1.avif") type("image/avif"),
  url("image2.jpg") type("image/jpeg")
);

Values

<image>

The <image> can be any image type except for an image set. The image-set() function may not be nested inside another image-set() function.

<string>

A URL to an image.

<resolution> Optional

<resolution> units include x or dppx, for dots per pixel unit, dpi, for dots per inch, and dpcm for dots per centimeter. Every image within an image-set() must have a unique resolution.

type(<string>) Optional

A valid MIME type string, for example "image/jpeg".

Formal syntax

<image-set()> = 
image-set( <image-set-option># )

<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?

<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>

<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )

<cross-fade()> =
cross-fade( <cf-image># )

<element()> =
element( <id-selector> )

<image-tags> =
ltr |
rtl

<image-src> =
<url> |
<string>

<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?

<id-selector> =
<hash-token>

Accessibility

Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.

Examples

Using image-set() to provide alternative background-image options

This example shows how to use image-set() to provide two alternative background-image options, chosen depending on the resolution needed: a normal version and a high-resolution version.

html
<div class="box"></div>
css
.box {
  width: 400px;
  height: 200px;
  background-repeat: no-repeat;
  background-size: cover;

  background-image: image-set(
    url("https://mdn.github.io/shared-assets/images/examples/balloons-small.jpg")
      1x,
    url("https://mdn.github.io/shared-assets/images/examples/balloons-landscape.jpg")
      2x
  );
}

Using image-set() to provide alternative image formats

In the next example the type() function is used to serve the image in AVIF and JPEG formats. If the browser supports avif, it will choose that version. Otherwise it will use the jpeg version.

html
<div class="box"></div>
css
.box {
  width: 400px;
  height: 200px;
  background-repeat: no-repeat;
  background-size: cover;

  background-image: image-set(
    "https://mdn.github.io/shared-assets/images/examples/balloons-landscape.avif"
      type("image/avif"),
    "https://mdn.github.io/shared-assets/images/examples/balloons-landscape.jpg"
      type("image/jpeg")
  );
}

Specifications

Specification
CSS Images Module Level 4
# image-set-notation

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
image-set()
Chrome – Partial support
Chrome 20 – 112 (Release date: 2012-06-26)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Chrome – Full support
Chrome 113 (Release date: 2023-05-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome – Full support
Chrome 113 (Release date: 2023-05-02)
footnote Full support
Edge – Partial support
Edge 79 – 112 (Release date: 2020-01-15)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Edge – Full support
Edge 113 (Release date: 2023-05-05)
prefix
prefix Implemented with the vendor prefix: -webkit-
Edge – Full support
Edge 113 (Release date: 2023-05-05)
footnote Full support
Firefox – Partial support
Firefox 88 – 88 (Release date: 2021-04-19)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Firefox – Full support
Firefox 90 (Release date: 2021-07-13)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox – Full support
Firefox 89 (Release date: 2021-06-01)
footnote Full support
Opera – Partial support
Opera 15 – 98 (Release date: 2013-07-02)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Opera – Full support
Opera 99 (Release date: 2023-05-16)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera – Full support
Opera 99 (Release date: 2023-05-16)
footnote Full support
Safari – Partial support
Safari 6 – 13.1 (Release date: 2012-07-25)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Safari – Partial support
Safari 10.1 – 13.1 (Release date: 2017-03-27)
footnote Partial support
footnote Support for url images only and x is the only supported resolution unit.
Safari – Partial support
Safari 14 – 16.6 (Release date: 2020-09-16)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote The type() function is not supported as an argument to image-set().
Safari – Partial support
Safari 14 – 16.6 (Release date: 2020-09-16)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Safari – Full support
Safari 17 (Release date: 2023-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari – Full support
Safari 17 (Release date: 2023-09-18)
footnote Full support
Chrome Android – Partial support
Chrome Android 25 – 112 (Release date: 2013-02-27)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Chrome Android – Full support
Chrome Android 113 (Release date: 2023-05-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
Chrome Android – Full support
Chrome Android 113 (Release date: 2023-05-02)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 88 – 88 (Release date: 2021-04-19)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Firefox for Android – Full support
Firefox for Android 90 (Release date: 2021-07-13)
prefix
prefix Implemented with the vendor prefix: -webkit-
Firefox for Android – Full support
Firefox for Android 89 (Release date: 2021-06-01)
footnote Full support
Opera Android – Partial support
Opera Android 14 – 75 (Release date: 2013-05-21)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Opera Android – Full support
Opera Android 76 (Release date: 2023-06-26)
prefix
prefix Implemented with the vendor prefix: -webkit-
Opera Android – Full support
Opera Android 76 (Release date: 2023-06-26)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 6 – 13.4 (Release date: 2012-09-10)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Safari on iOS – Partial support
Safari on iOS 10.3 – 13.4 (Release date: 2017-03-27)
footnote Partial support
footnote Support for url images only and x is the only supported resolution unit.
Safari on iOS – Partial support
Safari on iOS 14 – 16.6 (Release date: 2020-09-16)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote The type() function is not supported as an argument to image-set().
Safari on iOS – Partial support
Safari on iOS 14 – 16.6 (Release date: 2020-09-16)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 1.5 – 22 (Release date: 2013-09-25)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
Samsung Internet – Full support
Samsung Internet 23 (Release date: 2023-10-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
Samsung Internet – Full support
Samsung Internet 23 (Release date: 2023-10-18)
footnote Full support
WebView Android – Partial support
WebView Android 4.4 – 112 (Release date: 2013-12-09)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
WebView Android – Full support
WebView Android 113 (Release date: 2023-05-02)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView Android – Full support
WebView Android 113 (Release date: 2023-05-02)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 6 – 13.4 (Release date: 2012-09-10)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote Support for url images only and x is the only supported resolution unit.
WebView on iOS – Partial support
WebView on iOS 10.3 – 13.4 (Release date: 2017-03-27)
footnote Partial support
footnote Support for url images only and x is the only supported resolution unit.
WebView on iOS – Partial support
WebView on iOS 14 – 16.6 (Release date: 2020-09-16)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -webkit-
footnote The type() function is not supported as an argument to image-set().
WebView on iOS – Partial support
WebView on iOS 14 – 16.6 (Release date: 2020-09-16)
footnote Partial support
footnote The type() function is not supported as an argument to image-set().
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also