<image>

The <image> CSS data type represents a 2D image. There are two kinds of images: plain images, typically referenced using a URL, and dynamically-generated images, like those generated with <gradient> or element(). Images can be used with numerous CSS properties, such as background-image, border-image, content, list-style-image, and cursor.

Image types

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 with the aspect ratio closest 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.

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 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 The size of the element's border image area
cursor The browser-defined size matching the usual cursor size on the client's system
border-image-source ?
mask-image ?
shape-outside ?
mask-border-source ?
Replaced content, as when combining content with a pseudo-element (::after or ::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.

Syntax

An <image> can be represented in the following ways:

Examples

Valid images

url(test.jpg)                          /* The url() function, as long as test.jpg is an actual image */
linear-gradient(to bottom, blue, red)  /* A <gradient> */
element(#colonne3)                     /* A part of the webpage, used with the element() function,
                                          if colonne3 is an existing CSS id on the page. */

Invalid images

cervin.jpg                             /* An image file must be defined using the url() function. */
url(report.pdf)                        /* The file pointed by the url() function must be an image. */
element(#fakeid)                       /* If 'fakeid' is not an existing CSS ID on the page. */

Specifications

Specification Status Comment
CSS Image Values and Replaced Content Module Level 4
The definition of '<image>' in that specification.
Working Draft Add element()image(),  conic-gradient()repeating-conic-gradient(),  image-resolution
CSS Image Values and Replaced Content Module Level 3
The definition of '<image>' in that specification.
Candidate Recommendation Before CSS3, there was no explicitly defined <image> data type. Images could only be defined using the url() functional notations.

Browser compatibility

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
<uri> (Yes) (Yes) (Yes) (Yes) (Yes)
<gradient> (Yes)
limited to background-image & border-image & mask-image
(Yes)-webkit IE 10-ms (Yes) (Yes)
element() 4.0 (2.0) limited to background-image & background-moz No support No support No support No support
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
<uri> (Yes) (Yes) (Yes) (Yes) (Yes)
<gradient> (Yes)
limited to background-image & border-image & mask-image
? ? ? ?
element() 4.0 (2.0) limited to background-image & background-moz No support No support No support No support

See also

Document Tags and Contributors

 Last updated by: mfluehr,