Home >Web >HTML reference – elements and attributes >picture – image in several versions

picture – image in several versions

<picture><source srcset="…" type="image/avif"><img src="…" alt="…"></picture>

A wrapper for several versions of one image. The browser goes through the source elements in order and uses the first one that matches – by format (type) or condition (media). If none matches, it shows the image from img. It is always the img inside that is rendered: its alt, dimensions and styles apply to all versions.

  • Default display: display: inline
  • End tag: required
  • Content: zero or more source followed by one img
  • Where it can be used: anywhere phrasing content is allowed
  • DOM interface: HTMLPictureElement

Attributes

Only global attributes – everything important is in source and img.

Examples

Newer formats with a JPEG fallback:

<picture>
  <source srcset="/img/castle.avif" type="image/avif">
  <source srcset="/img/castle.webp" type="image/webp">
  <img src="/img/castle.jpg" alt="A white castle with two towers" width="800" height="533">
</picture>

A different, narrower crop of the photo on phones (art direction):

<picture>
  <source srcset="/img/castle-crop.jpg" media="(max-width: 600px)" width="400" height="500">
  <img src="/img/castle.jpg" alt="A white castle with two towers" width="800" height="533">
</picture>

Things to watch out for

  • The order of source elements decides – the first matching one wins. The most efficient format (AVIF) goes first.
  • Put styles and classes on img, not on picture – the image is the img.
  • Dimensions for a different crop (width, height on source) are supported by Chrome since 90, Firefox since 108 and Safari since 15 (as of October 2026).
  • When it is just the same image in different sizes, img with srcset and sizes is enough – picture is not needed.

Browser support

Baseline – widely available: in all major browsers since March 2016, considered widely available since September 2018. Since version: Chrome 38, Firefox 38, Safari 9.1. As of October 2026 (MDN browser-compat-data).

Related:
source – image or media source
img – image
figure – figure with caption