<image>
Quick Summary for image()
The <image> CSS data type represents a two-dimensional image.
Code Usage for image()
url(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 */ 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 */ 
More Details for image()

<image>

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.

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.

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 concerns

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.

MDN Understanding WCAG, Guideline 1.1 explanations Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0

Examples

Valid images

url(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 */ 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

nourl.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 resolutions */ 

Specifications

Specification
CSS Images Module Level 3 # image-values

See also

<gradient> element() image() image-set() cross-fade()

Last modified: Aug 12, 2021, by MDN contributors

Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Português (do Brasil)中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

font-variant-alternates

The font-variant-alternates CSS property controls the usage of alternate glyphs. These alternate glyphs may be referenced by alternative names defined in @font-feature-values.
annotation() css reference