Advanced Art Direction

Picture Element

Master the HTML picture element for advanced art direction, format optimization, and responsive image delivery with precise control over image selection.

What is the HTML <picture> element used for?

<picture> lets you offer alternative image sources and the browser uses the first matching <source>. It's used for modern formats with a fallback (AVIF, then WebP, then JPEG) and for art direction, such as a different crop on mobile. It must end with a normal <img>, which provides the alt, the size and the fallback.

<picture>
  <source type="image/avif" srcset="hero.avif">
  <source type="image/webp" srcset="hero.webp">
  <source media="(max-width: 600px)" srcset="hero-mobile.jpg">
  <img src="hero.jpg" alt="Team working together" width="1200" height="600">
</picture>

Art Direction & Format Control

The HTML picture element provides precise control over which image to display based on device characteristics, allowing for art direction and modern format delivery with graceful fallbacks.

Art Direction

Different images for different screen sizes and contexts

Format Control

Modern formats with automatic fallbacks

Smart Selection

Browser automatically selects optimal image

Picture Element Implementation

Comprehensive examples covering art direction, format optimization, media queries, and advanced responsive image techniques using the picture element.

Code Editor

<picture>
  <source media="(max-width: 500px)" srcset="https://picsum.photos/id/1035/400/400">
  <source type="image/webp" srcset="https://picsum.photos/id/1035/800/400.webp">
  <img src="https://picsum.photos/id/1035/800/400" alt="Waterfall" width="800" height="400">
</picture>
<p id="out">Resize the preview below 500px to get the square crop.</p>

Preview

Best Practices & Guidelines

Source Order Matters

  • • Most specific conditions first
  • • Format sources before media queries
  • • Fallback img element last
  • • Browser uses first matching source

Performance Tips

  • • Use modern formats (AVIF, WebP)
  • • Optimize image dimensions
  • • Consider lazy loading
  • • Minimize source variations

Picture Element Checklist

  • Always include img fallback
  • Use descriptive alt text
  • Test across devices
  • Validate media queries
  • Optimize for performance
  • Consider accessibility

The picture Element — step by step

1 / 4
1

Use picture for art direction

The picture element wraps multiple source elements and a fallback img element. The browser evaluates each source in order and uses the first match. This enables art direction — serving different image crops for different screen sizes.

1 of 4
🔍picture vs srcset: Different Use Cases
Use srcset on img for resolution switching — serving the same image at different sizes for different pixel densities. Use picture with source elements for art direction — serving completely different images based on viewport size or format support. Both can be combined for maximum control.

🎯 Quick Check

What is the purpose of the type attribute on a source element inside picture?

Picture Element Mastered!

Excellent! You've mastered the picture element with advanced art direction and format control. Ready to explore Image Maps for interactive images?

HTML picture Element: summary

Key points

  • Style the inner <img>, not the <picture> element.
  • Sources are checked in order, so put the most preferred format first.
  • Each <source> can also have its own srcset and sizes.

Frequently asked questions

›Do I still need an img inside picture?

Yes. The <img> is required: it's what actually renders, and it carries the alt text and the fallback image.