<picture>: The Picture element

You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

The HTML <picture> element contains zero or more <source> elements and one <img> element to provide 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.

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 of the page, the characteristics of the display device, etc. The <img> element serves two purposes: it describes the size and other attributes of the image and its  presentation, and it provides a fallback in case none of the offered <source> elements are able to provide a usable image.

Common use cases for <picture>:

  • Art direction — cropping or modifying images for different media conditions (for example, loading a simpler version of an image which has too many details, on smaller displays).
  • Offering different image formats when certain formats are not supported by all browsers.
  • Saving on bandwidth and making pages load faster by loading the appropriate version of images with the right size and dimensions based on the viewer's display,

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.
Permitted ARIA roles None
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 media condition evaluates to false, its <source> element is skipped.

<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 indicates a set of possible images for the browser to use based on size. It is composed from a URL of the image and either a width descriptor followed by a w, such as 300w or a pixel densite descriptor followed by an x, such as 2x to serve a high-res image for high-DPI screens.

<picture>
  <source srcset="logo-768.png 768w, logo-768-1.5x.png 1.5px">
  <source srcset="logo-480.png, logo-480-2x.png 2x">
  <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.

<picture>
  <source srcset="logo.webp" type="image/webp">
  <img src="logo.png" alt="logo">
</picture>

Specifications

Specification Status Comment
HTML Living Standard
The definition of '<picture>' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
pictureChrome Full support 38Edge Full support 13Firefox Full support 38
Full support 38
No support 32 — 52
Disabled
Disabled From version 32 until version 52 (exclusive): this feature is behind the dom.image.picture.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 25Safari Full support 9.1WebView Android Full support 38Chrome Android Full support 38Firefox Android Full support 38
Full support 38
No support 32 — 52
Disabled
Disabled From version 32 until version 52 (exclusive): this feature is behind the dom.image.picture.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 25Safari iOS Full support 9.3Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
User must explicitly enable this feature.
User must explicitly enable this feature.

See also