<image> CSS type

Baseline Widely available *

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

* Some parts of this feature may have varying levels of support.

The <image> CSS data type represents a two-dimensional image.

Syntax

The <image> data type can be represented with any of the following:

  • An image denoted by the <url> data type
  • A <gradient> data type
  • A part of the webpage, defined by the element() function
  • An image, image fragment or solid patch of color, defined by the image() function
  • A blending of two or more images defined by the cross-fade() function.
  • A selection of images chosen based on resolution defined by the image-set() function.
  • Generated by a paint worklet with the paint() function.

Description

CSS can handle the following kinds of images:

  • Images with intrinsic dimensions (a natural size), like a JPEG, PNG, or other raster format.
  • Images with multiple intrinsic dimensions, existing in multiple versions inside a single file, like some .ico formats. (In this case, the intrinsic dimensions will be those of the image largest in area and the aspect ratio most similar to the containing box.)
  • Images with no intrinsic dimensions but with an intrinsic aspect ratio between its width and height, like an SVG or other vector format.
  • Images with neither intrinsic dimensions, nor an intrinsic aspect ratio, like a CSS gradient.

Concrete size

CSS determines an object's concrete size using (1) its intrinsic dimensions; (2) its specified size, defined by CSS properties like width, height, or background-size; and (3) its default size, determined by the kind of property the image is used with:

Kind of Object (CSS Property) Default object size
background-image The size of the element's background positioning area
list-style-image The size of a 1em character
border-image-source The size of the element's border image area
cursor The browser-defined size matching the usual cursor size on the client's system
mask-image ?
shape-outside ?
mask-border-source ?
symbols() for @counter-style At risk feature. If supported, the browser-defined size matching the usual cursor size on the client's system
content for a pseudo-element (::after/::before) A 300px × 150px rectangle

The concrete object size is calculated using the following algorithm:

  • If the specified size defines both the width and the height, these values are used as the concrete object size.
  • If the specified size defines only the width or only the height, the missing value is determined using the intrinsic ratio, if there is any, the intrinsic dimensions if the specified value matches, or the default object size for that missing value.
  • If the specified size defines neither the width nor the height, the concrete object size is calculated so that it matches the intrinsic aspect ratio of the image but without exceeding the default object size in any dimension. If the image has no intrinsic aspect ratio, the intrinsic aspect ratio of the object it applies to is used; if this object has none, the missing width or height are taken from the default object size.

Note: Not all browsers support every type of image on every property. See the browser compatibility section for details.

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.

Formal syntax

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

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

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

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

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

<image-tags> =
ltr |
rtl

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

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

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

<id-selector> =
<hash-token>

Examples

Valid images

css
url("test.jpg")               /* A <url>, as long as test.jpg is an actual image */
linear-gradient(blue, red)  /* A <gradient> */
element(#real-id)            /* A part of the webpage, referenced with the element() function,
                               if "real-id" is an existing ID on the page */
image(ltr "arrow.png#xywh=0,0,16,16", red)
                            /* A section 16x16 section of <url>, starting from the top, left of the original
                               image as long as arrow.png is a supported image, otherwise a solid
                               red swatch. If language is rtl, the image will be horizontally flipped. */
cross-fade(20% url("twenty.png"), url("eighty.png"))
                            /* cross faded images, with twenty being 20% opaque
                               and eighty being 80% opaque. */
image-set("test.jpg' 1x, 'test-2x.jpg" 2x)
                            /* a selection of images with varying resolutions */

Invalid images

css
"no-url.jpg"           /* An image file must be defined using the url() function. */
url("report.pdf")      /* A file pointed to by the url() function must be an image. */
element(#fakeid)     /* An element ID must be an existing ID on the page. */
image(z.jpg#xy=0,0)  /* The spatial fragment must be written in the format of xywh=#,#,#,# */
image-set("cat.jpg" 1x, "dog.jpg" 1x) /* every image in an image set must have a different resolution */

Specifications

Specification
CSS Images Module Level 3
# image-values

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>
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 2 (Release date: 1996-07-14)
footnote Full support
Safari – Full support
Safari 1 (Release date: 2003-06-23)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 11 (Release date: 2011-03-22)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
cross-fade()
Chrome – Full support
Chrome 17 (Release date: 2012-02-08)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
Firefox – No support
Firefox
footnote
footnote See bug 1657516
Opera – Full support
Opera 15 (Release date: 2013-07-02)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
Safari – Full support
Safari 5.1 (Release date: 2011-07-20)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
Safari – Full support
Safari 10 (Release date: 2016-09-20)
footnote
footnote Supports the original dual-image with percentage implementation only.
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1657516
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
Safari on iOS – Full support
Safari on iOS 5 (Release date: 2011-10-12)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
Safari on iOS – Full support
Safari on iOS 9.3 (Release date: 2016-03-21)
footnote
footnote Support for the original dual-image with percentage implementation only.
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
footnote See bug 40470742 for supporting the unprefixed cross-fade() function.
WebView on iOS – Full support
WebView on iOS 5 (Release date: 2011-10-12)
prefix , footnote
prefix Implemented with the vendor prefix: -webkit-
footnote Supports the original dual-image with percentage implementation only.
WebView on iOS – Full support
WebView on iOS 9.3 (Release date: 2016-03-21)
footnote
footnote Support for the original dual-image with percentage implementation only.
element()
Experimental
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Partial support
Firefox 4 – 28 (Release date: 2011-03-22)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -moz-
footnote -moz-element() is limited to background-image and background.
Firefox – Partial support
Firefox 29 – 56 (Release date: 2014-04-29)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -moz-
footnote -moz-element() is limited to background-image, background, border-image and border-image-source.
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
prefix
prefix Implemented with the vendor prefix: -moz-
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – Partial support
Firefox for Android 4 – 28 (Release date: 2011-03-29)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -moz-
footnote -moz-element() is limited to background-image and background.
Firefox for Android – Partial support
Firefox for Android 29 – 59 (Release date: 2014-04-29)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: -moz-
footnote -moz-element() is limited to background-image, background, border-image and border-image-source.
Firefox for Android – Full support
Firefox for Android 60 (Release date: 2018-05-09)
prefix
prefix Implemented with the vendor prefix: -moz-
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
filter()
Chrome – No support
Chrome
footnote
footnote See bug 41208242
Edge – No support
Edge
footnote
footnote See bug 41208242
Firefox – No support
Firefox
footnote
footnote See bug 1191043
Opera – No support
Opera
footnote
footnote See bug 41208242
Safari – No support
Safari 9 – 9 (Release date: 2015-09-30)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari – Full support
Safari 9.1 (Release date: 2016-03-21)
footnote Full support
Chrome Android – No support
Chrome Android
footnote
footnote See bug 41208242
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1191043
Opera Android – No support
Opera Android
footnote
footnote See bug 41208242
Safari on iOS – No support
Safari on iOS 9 – 9 (Release date: 2015-09-16)
prefix
prefix Implemented with the vendor prefix: -webkit-
Safari on iOS – Full support
Safari on iOS 9.3 (Release date: 2016-03-21)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote
footnote See bug 41208242
WebView Android – No support
WebView Android
footnote
footnote See bug 41208242
WebView on iOS – No support
WebView on iOS 9 – 9 (Release date: 2015-09-16)
prefix
prefix Implemented with the vendor prefix: -webkit-
WebView on iOS – Full support
WebView on iOS 9.3 (Release date: 2016-03-21)
footnote Full support
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
paint()
Chrome – Full support
Chrome 65 (Release date: 2018-03-06)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1302328
Opera – Full support
Opera 52 (Release date: 2018-03-22)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 190217
Chrome Android – Full support
Chrome Android 65 (Release date: 2018-03-06)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1302328
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 190217
Samsung Internet – Full support
Samsung Internet 9.2 (Release date: 2019-04-02)
footnote Full support
WebView Android – Full support
WebView Android 65 (Release date: 2018-03-06)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 190217
Supports additional parameters to pass to the paintWorklet
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox
footnote
footnote See bug 1302328
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote
footnote See bug 190217
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1302328
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 190217
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 190217

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also