Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. CSS
  3. Reference
  4. Values
  5. <image>

<image>

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>CSSdata 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 theelement() function
  • An image, image fragment or solid patch of color, defined by theimage() function
  • A blending of two or more images defined by thecross-fade() function.
  • A selection of images chosen based on resolution defined by theimage-set() function.
  • Generated by apaint worklet with thepaint() function.

Description

CSS can handle the following kinds of images:

  • Images withintrinsic dimensions (a natural size), like a JPEG, PNG, or otherraster format.
  • Images withmultiple 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 theaspect ratio most similar to the containing box.)
  • Images with no intrinsic dimensions but withan intrinsic aspect ratio between its width and height, like an SVG or othervector format.
  • Images withneither intrinsic dimensions, nor an intrinsic aspect ratio, like a CSS gradient.

CSS determines an object'sconcrete size using (1) itsintrinsic dimensions; (2) itsspecified size, defined by CSS properties likewidth,height, orbackground-size; and (3) itsdefault size, determined by the kind of property the image is used with:

Kind of Object (CSS Property)Default object size
background-imageThe size of the element's background positioning area
list-style-imageThe size of a1em character
border-image-sourceThe size of the element's border image area
cursorThe browser-defined size matching the usual cursor size on the client's system
mask-image?
shape-outside?
mask-border-source?
symbols() for @counter-styleAt 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 definesboth the width and the height, these values are used as the concrete object size.
  • If the specified size definesonly 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 definesneither 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 thebrowser 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

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp