The <image>
CSS data type represents a two-dimensional image. There are two kinds of images: plain images, referenced with a <url>
, and dynamically-generated images, generated with <gradient>
or element()
. Images can be used with numerous CSS properties, such as background-image
, border-image
, content
, cursor
, and list-style-image
.
CSS can handle the following kinds of images:
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:
The <image>
data type can be represented with any of the following:
<url>
data type<gradient>
data typeelement()
functionurl(test.jpg) /* A <url>, as long as test.jpg is an actual image */ linear-gradient(blue, red) /* A <gradient> */ element(#realid) /* A part of the webpage, referenced with the element() function, if "realid" is an existing ID on the page */
cervin.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. */
Specification | Status | Comment |
---|---|---|
CSS Images Module Level 4 The definition of '<image>' in that specification. | Working Draft | Adds element() , image() , conic-gradient() , repeating-conic-gradient() , and image-resolution . |
CSS Images Module Level 3 The definition of '<image>' in that specification. | Candidate Recommendation | Initial definition. Before this, there was no explicitly defined <image> data type. Images could only be defined using the url() functional notation. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | Yes | ? | Yes | Yes | Yes | Yes |
<gradient> |
Yes -webkit- | ? | Yes1 | 10 -ms- | Yes | Yes |
element() |
No | ? | 4 -moz- 2 | No | No | No |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | ? | ? | Yes | Yes | Yes | Yes |
<gradient> |
? | ? | ? | Yes1 | ? | ? | ? |
element() |
No | ? | ? | 4 -moz- 2 | No | No | No |
1. Gradients are limited to background-image
, border-image
, and mask-image
.
2. element()
is limited to background-image
and background
.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/image