Course contentsShow
← Web Development
Lesson 1230 of 2,98222. Responsive Images and MediaFree lesson

Picture vs img srcset: When to Use Which

Distinguish between resolution switching (srcset) and art direction (picture) use cases.

Picture vs img srcset: When to Use Which

You'll learn: How to decide between srcset and <picture> based on whether you need resolution switching or art direction.

The Core Difference

Think of srcset and <picture> as two tools for two different jobs:

  • srcset is for resolution switching: You have the same image at different sizes, and the browser picks the best one for the viewport width and screen density. It's like having small, medium, and large versions of the same photo.

  • <picture> is for art direction: You have different images for different contexts—cropped differently, reframed, or showing different content entirely. It's like having a landscape photo for desktop but a portrait crop for mobile that focuses on the subject.

When to Use srcset

Use srcset (on an <img> tag) when:

  • You're serving the same visual content at different resolutions
  • The browser can choose the most efficient image
  • Examples: product photos, blog post images, generic content images

When to Use <picture>

Use <picture> when:

  • Different layouts need different compositions (wide vs tall crops)
  • You need format fallbacks (WebP with JPEG backup)
  • Mobile users should see a different focal point than desktop users
  • Examples: hero banners, editorial images where cropping matters

The Practical Test

Ask yourself: "If I showed both versions side-by-side, would they look like different compositions or just different sizes?" Different compositions = <picture>. Different sizes = srcset.

You can also combine both! A <picture> element can contain <source> tags that themselves use srcset for resolution switching within each art-directed breakpoint.

Key Takeaway: Use srcset for simple resolution scaling; use <picture> when the image itself needs to change based on context or format requirements.