Course contentsShow
← Web Development
Lesson 2012 of 2,98237. Image and Asset OptimizationFree lesson

Art Direction with the Picture Element

Use <picture> with multiple <source> elements to serve entirely different images based on media queries.

Art Direction with the Picture Element

You'll learn how to serve entirely different images based on screen size or context using the <picture> element.

What is Art Direction?

While srcset and sizes help browsers pick different resolutions of the same image, art direction solves a different problem: serving completely different images based on the viewing context. Think of it like this: a wide landscape photo might look great on desktop, but on mobile you might want a tightly cropped portrait version that focuses on the subject instead.

The <picture> Element

The <picture> element acts as a wrapper that lets you define multiple <source> elements, each with its own media query. The browser evaluates them top-to-bottom and uses the first match:

<picture>
  <source 
    media="(min-width: 1024px)" 
    srcset="hero-wide.jpg">
  <source 
    media="(min-width: 768px)" 
    srcset="hero-medium.jpg">
  <img 
    src="hero-narrow.jpg" 
    alt="Mountain landscape">
</picture>

How It Works

  1. The browser checks each <source> in order
  2. When a media query matches, it uses that source's srcset
  3. The <img> element is required as the fallback—it's what actually displays
  4. You can combine this with srcset descriptors for resolution switching within each breakpoint

Real-World Use Case

A hero banner might show a full group photo on desktop, but on mobile you crop to just the speaker's face. These aren't just different sizes—they're editorially different choices:

<picture>
  <source media="(min-width: 768px)" srcset="team-full.jpg">
  <img src="speaker-portrait.jpg" alt="Team photo">
</picture>

Key Takeaway: Use <picture> with multiple <source> elements when you need to serve completely different images (not just different resolutions) based on media queries—perfect for art direction scenarios where cropping or composition needs to change.