HTML <picture> Tag

Beginner
5 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <picture> element contains zero or more <source> elements and one required <img>. The browser picks the best matching source; otherwise it uses the <img> src.

Common jobs: art direction (different crops per viewport), format fallback (AVIF/WebP then JPEG), and saving bandwidth. For the same image at 1x/2x densities, prefer srcset on <img> alone.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about March 2016.

img still displays.

The selected URL is shown in the space of the <img>. Put alt, width/height, and CSS like object-fit on that <img>.

HTML Syntax

syntax.html
<picture> <source>… <img></picture>

Both start and end tags are required. Order: any number of <source>, then exactly one <img>.

Attributes

<picture> has no element-specific attributes. Selection uses nested <source> (and the required <img>):

AttributeDescriptionTry it
media (on source)Media condition for art direction (for example (width >= 600px))Try it
type (on source)MIME type so unsupported formats are skipped (for example image/webp)Try it
srcset (on source / img)Candidate URLs with width (w) or density (x) descriptorsTry it
sizes (with width srcset)Layout width hints so the browser picks the right w candidateTry it

Global Attributes

The <picture> tag also supports the Global Attributes in HTML.

Live Preview

Switch common <picture> patterns. Resize the browser window on the art-direction example to see the source change.

A real <picture>. The nested <img> always carries alt.

Picture
Demo responsive image

Wide viewports load nature-pattern; narrower loads the circle image.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Art Direction with media

Serve a different asset when the viewport is wide enough.

HTML
<picture>
  <source srcset="/images/nature-pattern.jpg" media="(width >= 600px)">
  <img src="/images/circle_image.jpg" alt="Demo responsive image" width="240" height="160">
</picture>
Try It Yourself

How It Works

  1. Open <picture> as the wrapper.
  2. Add a <source> with srcset and a media condition.
  3. Finish with <img> — required fallback plus alt.
  4. Resize the window to see which URL the browser selects.

Example 2 — Modern Format Fallback

Offer WebP first; browsers that cannot decode it skip to the JPEG/PNG <img>.

HTML
<picture>
  <source srcset="/images/html-picture-tag.webp" type="image/webp">
  <img src="/images/javascript.png" alt="HTML picture tag illustration" width="320" height="168">
</picture>
Try It Yourself

How It Works

  1. List newer formats first with type (for example image/webp or image/avif).
  2. Skip unsupported types — the browser moves to the next <source> or the <img>.
  3. Keep a widely supported fallback on <img src>.
  4. Write alt once on that <img>.

Example 3 — Light / Dark with prefers-color-scheme

Swap assets for light and dark themes without JavaScript.

HTML
<picture>
  <source srcset="/images/nature-pattern.jpg" media="(prefers-color-scheme: dark)">
  <source srcset="/images/javascript.png" media="(prefers-color-scheme: light)">
  <img src="/images/javascript.png" alt="Theme-aware logo" width="128" height="128">
</picture>
Try It Yourself

How It Works

  1. Add a dark-theme <source> with prefers-color-scheme: dark.
  2. Add a light-theme <source> the same way.
  3. Keep a default <img> for browsers without a preference match.
  4. Toggle OS/browser theme to see which asset loads.

Example 4 — Density with img srcset (No picture)

When the image is the same crop, density descriptors on <img> are enough — no wrapper needed.

HTML
<img
  src="/images/javascript.png"
  srcset="/images/javascript.png 1x, /images/javascript.png 2x"
  alt="JavaScript logo"
  width="128"
  height="128"
>
Try It Yourself

How It Works

  1. Skip <picture> when you only need resolution switching.
  2. List candidates in srcset with 1x / 2x (or width w + sizes).
  3. Keep src as a reliable fallback URL.
  4. Use <picture> only when crops or formats must differ.

Edge Cases & Pitfalls

Most picture mistakes are missing img, wrong alt placement, or overusing the wrapper.

required

Always include img

<picture> without a trailing <img> is incomplete. The image that paints is that <img>.

a11y

alt on img only

Do not put alt on <picture> or <source>. Screen readers use the nested image.

css

Style the img

Use object-fit and object-position on the child <img>, not on <picture>.

srcset

Do not mix w and x

In one srcset, use either width descriptors or density descriptors — not both. Duplicate descriptors are invalid.

choice

Not always needed

Same crop, different DPI? Prefer <img srcset>. Reserve <picture> for art direction or format lists.

Browser Support

The <picture> element is core HTML in every modern browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<picture>

Widely available since about March 2016. Chrome, Firefox, Safari, Edge, and Opera all support picture with source and img.

96% Global support (approx.)
Google Chrome 38+
Full support
Mozilla Firefox 38+
Full support
Apple Safari 9.1+
Full support
Microsoft Edge 13+
Full support
Opera 25+
Full support
Samsung Internet All
Full support
Internet Explorer —
Not supported
<picture> Widely supported

Bottom line: Safe for modern sites. Always keep a working img fallback for older clients.

Key Takeaways

  • Structure: zero or more <source>, then one <img>.
  • Jobs: art direction (media) and format lists (type).
  • Display: the nested <img> shows the chosen URL and holds alt.
  • Simpler case: density-only needs → <img srcset> without picture.

One line: use <picture> when sources must differ by layout or format; always end with an <img>.

Default CSS Settings

<picture> itself has no special chrome. The visible box is the nested image:

default.css
picture {
  display: inline;
}

/* Style the img that actually paints */
picture > img {
  /* object-fit / object-position go here */
}

Exact UA values can vary; treat the <img> as the styling target.

Frequently Asked Questions

The picture element offers alternative images for different layouts or formats. Zero or more source elements come first; one img is required as the fallback and the element that actually displays.
No. It only supports global attributes. Selection is controlled by attributes on nested source elements (and the required img).
Use picture for art direction (different crops or assets per media) or format negotiation (AVIF/WebP then JPEG). For the same image at different densities, img srcset is often enough.
Always on the img inside picture. The picture and source elements do not take alt.
The browser uses the img element’s src (and any srcset/sizes on that img).
Apply object-fit and object-position on the child img, not on picture.

Next: plaintext

See why the obsolete plaintext element should not be used.

plaintext tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful