The <image>
CSS data type represents a 2D image. There are two kinds of images in CSS: plain static images, often referenced using a URL, and dynamically-generated images like gradients or representations of parts of the tree.
CSS can handle different kinds of images:
CSS determines the concrete object size using these intrinsic dimensions, the specified size defined by CSS properties like width
, height
or background-size
, and the default object size defined 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 character of 1em
|
border-image | The size of the element's border image area |
cursor | A browser-defined size matching the usual size of a cursor on the used system |
Replaced content like with the combination of the CSS content propertyin combination with the CSS pseudo-elements ::after and ::before
| A 300px × 150px rectangle |
The concrete object size is calculated using the following algorithm:
Images can be used with numerous CSS properties like background-image
, border-image
, content
, list-style-image
or cursor
.
An <image>
CSS data type represents may be one of the following:
<uri>
data type and the url()
function;<gradient>
;element()
function.These are valid image values:
url(test.jpg) /* The url() function, as long as test.jpg is an image */ linear-gradient(to bottom, blue, red) /* A <gradient> */ element(#colonne3) /* A part of the page, used with the element() function, if colonne3 is an existing CSS id on the page. */
These are invalid image values:
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. */
Specification | Status | Comment |
---|---|---|
CSS Image Values and Replaced Content Module Level 3 The definition of '<image>' in that specification. | Candidate Recommendation | Before CSS3, there wasn't an explicitly-defined <image> data type. Images could only be defined using the url() functional notations. |
Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
<uri> | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
<gradient> |
(Yes) limited to background-image & background -moz
| (Yes)-webkit | IE 10-ms | (Yes)-o | (Yes)-webkit |
element() | 4.0 (2.0) limited to background-image & background -moz
| ? | ? | ? | ? |
Feature | Firefox Mobile (Gecko) | Android | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
<uri> | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
<gradient> |
(Yes) limited to background-image & background -moz
| ? | ? | ? | ? |
element() | 4.0 (2.0) limited to background-image & background -moz
| ? | ? | ? | ? |
<gradient>
, linear-gradient()
, radial-gradient()
, repeating-linear-gradient()
, repeating-radial-gradient()
element()
© 2005–2017 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