From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/html/element%2Fpicture.html | 108 ++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 devdocs/html/element%2Fpicture.html (limited to 'devdocs/html/element%2Fpicture.html') diff --git a/devdocs/html/element%2Fpicture.html b/devdocs/html/element%2Fpicture.html new file mode 100644 index 00000000..3beeaf09 --- /dev/null +++ b/devdocs/html/element%2Fpicture.html @@ -0,0 +1,108 @@ +

<picture>: The Picture element

+

The <picture> HTML element contains zero or more <source> elements and one <img> element to offer alternative versions of an image for different display/device scenarios.

The browser will consider each child <source> element and choose the best match among them. If no matches are found—or the browser doesn't support the <picture> element—the URL of the <img> element's src attribute is selected. The selected image is then presented in the space occupied by the <img> element.

+
+

Try it

+
+

To decide which URL to load, the user agent examines each <source>'s srcset, media, and type attributes to select a compatible image that best matches the current layout and capabilities of the display device.

The <img> element serves two purposes:

  1. It describes the size and other attributes of the image and its presentation.
  2. It provides a fallback in case none of the offered <source> elements are able to provide a usable image.

Common use cases for <picture>:

If providing higher-density versions of an image for high-DPI (Retina) display, use srcset on the <img> element instead. This lets browsers opt for lower-density versions in data-saving modes, and you don't have to write explicit media conditions.

Content categories +Flow content, phrasing content, embedded content
Permitted content Zero or more <source> elements, followed by one <img> element, optionally intermixed with script-supporting elements.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that allows embedded content.
Implicit ARIA role No corresponding role
Permitted ARIA roles No role permitted
DOM interface HTMLPictureElement
+
+

Attributes

+

This element includes only global attributes.

+

Usage notes

+
+

You can use the object-position property to adjust the positioning of the image within the element's frame, and the object-fit property to control how the image is resized to fit within the frame.

Note: Use these properties on the child <img> element, not the <picture> element.

+
+

Examples

+

These examples demonstrate how different attributes of the <source> element change the selection of the image inside <picture>.

+

The media attribute

+
+

The media attribute specifies a media condition (similar to a media query) that the user agent will evaluate for each <source> element.

If the <source>'s media condition evaluates to false, the browser skips it and evaluates the next element inside <picture>.

+

html

+
<picture>
+  <source srcset="mdn-logo-wide.png" media="(min-width: 600px)" />
+  <img src="mdn-logo-narrow.png" alt="MDN" />
+</picture>
+
+
+
+

The srcset attribute

+
+

The srcset attribute is used to offer list of possible images based on size.

It is composed of a comma-separated list of image descriptors. Each image descriptor is composed of a URL of the image, and either:

+

html

+
<picture>
+  <source srcset="logo-768.png, logo-768-1.5x.png 1.5x" />
+  <img src="logo-320.png" alt="logo" />
+</picture>
+
+
+
+

The type attribute

+
+

The type attribute specifies a MIME type for the resource URL(s) in the <source> element's srcset attribute. If the user agent does not support the given type, the <source> element is skipped.

+

html

+
<picture>
+  <source srcset="photo.avif" type="image/avif" />
+  <source srcset="photo.webp" type="image/webp" />
+  <img src="photo.jpg" alt="photo" />
+</picture>
+
+
+
+

Specifications

+
+ + +
Specification
HTML Standard
# the-picture-element
+

Browser compatibility

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on IOSSamsung Internet
picture381338No259.1383838259.33.0
+

See also

+
+

+ © 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
+ https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture +

+
-- cgit v1.2.3