The picture Element and Art Direction
Use picture and source to change the crop of an image by viewport or to offer modern formats with a fallback, and see how first-match selection behaves.
The picture Element and Art Direction
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- `srcset` lets the browser pick a size of the same picture. `<picture>` with `<source media>` lets you pick a different picture, such as a tighter crop on a phone. That is art direction.
- The browser takes the first `<source>` whose `media` (and `type`) matches. In a test with two matching sources, the first one was loaded.
- A `<picture>` always needs an `<img>` inside it. The `img` carries `alt`, `width`, `height` and the fallback `src`. In a test, a `<picture>` with only a `<source>` rendered nothing.
- Selection follows the viewport. In a test a page at 500px loaded the 400-wide file, 700px the 800-wide, 1000px the 1600-wide, and shrinking back to 500px loaded the 400-wide file again.
- Use `type` on a `<source>` for formats like AVIF or WebP. A browser that cannot decode the type skips the source and falls through to the next one.
When a smaller copy is not enough
Say your hero image is a wide photo of a runner on a track, taken from a distance. On a laptop it looks great. On a phone, scaled to fit, the runner is a few pixels tall. A smaller file, which is what srcset gives you, doesn’t fix that, since it’s the same picture. What you want is a different picture: a tight crop of the runner for narrow screens.
That’s art direction, and it’s what <picture> is for. A photographer picks the crop for each page size. The browser just follows your instructions.
<picture>
<source media="(min-width: 900px)" srcset="runner-wide.jpg">
<source media="(min-width: 600px)" srcset="runner-square.jpg">
<img src="runner-tall.jpg" alt="A runner leaning into the final bend" width="400" height="600">
</picture>
The browser reads the sources top to bottom, takes the first one whose condition is true, and puts that file into the <img>. If none match, the <img>’s own src is used.
What the tests showed
I ran this in headless Chromium 159 with three differently shaped files and measured currentSrc and the natural size of the image:
| Viewport | File that loaded |
|---|---|
| 500px | the 400 by 600 img fallback |
| 700px | the 800 by 800 source |
| 1000px | the 1600 by 900 source |
| back to 500px | the 400 by 600 fallback again |
Two more results:
- With two sources that both matched (
min-width: 400pxlisted beforemin-width: 300px, at 500px), the first one’s file loaded. Order is meaningful, so write the most specific condition first. - A
<picture>containing only a<source>, noimg, rendered nothing: no box and no node in the accessibility tree. Theimgis not optional.
That second point is a design rule too. The img holds everything about the image itself: alt, width, height, loading, class names. The source elements only choose the file. Putting alt on a source does nothing, and the alt text lesson applies unchanged. The switch also followed the window: unlike the srcset case in the previous lesson, where a larger file was kept after shrinking, this one went back to the fallback when the condition stopped matching.
Combining with srcset
Each source can have its own srcset and sizes, so you can do art direction and resolution switching together: a tall crop in three sizes below 600px, a wide crop in three sizes above. The media attribute accepts the same conditions as a CSS media query, which is how the browser decides.
Format fallback with type
The second use is format choice. Newer formats such as AVIF and WebP compress better, but not every browser decodes every format. The type attribute lets you offer one safely:
<picture>
<source type="image/avif" srcset="photo.avif">
<source type="image/webp" srcset="photo.webp">
<img src="photo.jpg" alt="..." width="800" height="600">
</picture>
A browser that supports a listed type uses the first match, and one that doesn’t skips it. In my test, a source marked with a made-up type (image/x-fake) was skipped, and the next source with a real type was chosen. Check support for your audience: the Baseline data in web-features lists AVIF as widely available from July 2026 and WebP from March 2023. Whether to bother with three formats is a performance call; see HTML performance and rendering cost.
What the video covers
The embed is Chrome for Developers’ “Responsive images & art direction - Designing in the Browser” (December 2021, about 12 minutes), hosted by Una Kravets. Its chapters are intro (0:00), media aspect ratio (1:24), preventing layout shift (4:56) and art direction (6:42). It is a design-focused episode rather than a picture reference, and I could not read a transcript, so I describe it only from the chapters and description. The type fallback and the source-order results are this lesson’s own. Kevin Powell’s 2018 picture video, 21 minutes, is the deeper link and is more of a reference on the element.
Where this fits
This builds on srcset and sizes. Next, lazy loading and decoding is about when the chosen file is fetched. For the CSS side of cropping, see aspect ratio and responsive media.
Check yourself
A wide hero photo is unreadable on a phone because the subject becomes tiny. Which tool fixes it, `srcset` or `picture`?
`picture`. A smaller version of the same photo does not help, since the subject is still tiny. You need a different crop on narrow screens: `<source media="(min-width: 800px)" srcset="wide.jpg">` with a portrait or tightly cropped `<img src>` as the default.
Where do `alt` and `width`/`height` go in a `<picture>`?
On the inner `<img>`. The `<source>` elements only choose which file the `img` shows. In a test a `<picture>` without an `img` produced nothing in the accessibility tree and no box on screen.
Two `<source>` elements both match the current viewport. Which one is used?
The first one in document order. In a test with `min-width: 400px` listed before `min-width: 300px` at a 500px viewport, the first source's file loaded. Order sources from most specific to least, with the `img` as the fallback.
How do you serve AVIF to browsers that support it and JPEG to the rest?
List `<source type="image/avif" srcset="a.avif">` first and put a JPEG in the `<img>`. A browser that supports the type uses the first source. Browsers that do not skip it. Add a WebP `source` between them if you want an extra step.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.