Responsive Images in 2026: srcset, picture, and AVIF

Responsive Images: srcset, picture, and AVIF

Responsive images solve three independent problems — resolution, format, and art direction. A decision tree for which HTML primitive to apply when, with LCP coordination.

Responsive images solve three independent problems — resolution, format, and art direction — and mixing the techniques without a decision tree leads to over-engineering. Use <img srcset + sizes> for resolution switching, <picture> with media for different crops per breakpoint, and <picture> with type for AVIF (Baseline 2024) and WebP format negotiation. Then pair fetchpriority, loading, and explicit dimensions to protect LCP and CLS.

What "responsive image" actually means

The phrase covers three distinct dimensions that have to be designed separately, even though they often appear in the same markup.

The first is resolution: the same image at different display widths and pixel densities, so a 4K monitor and a 320 CSS px phone do not both download a 2000-pixel JPEG. The second is format: AVIF, WebP, and JPEG produce different byte counts at similar perceived quality, and the goal is for each browser to get the smallest format it can render — with <picture>, by listing the smaller formats first. The third is art direction: a wide landscape composition for desktop and a tighter square crop for mobile, because the same picture cropped at different aspect ratios tells different stories.

Each dimension has its own HTML primitive. Treating them as one problem — "make the image responsive" — is what produces 200-line <picture> blocks that nobody can maintain. Picking the right primitive per dimension keeps the markup proportionate to the requirement.

Resolution switching with srcset and sizes

For the common case — the same image at multiple display sizes — <img> with srcset and sizes is enough.

html
<img
  src="hero-800.jpg"
  srcset="hero-400.jpg 400w,
          hero-800.jpg 800w,
          hero-1600.jpg 1600w,
          hero-2400.jpg 2400w"
  sizes="(width >= 60em) 50vw, 100vw"
  alt="Modular wooden type blocks on a printer's tray."
  width="1600"
  height="900">

Two attributes do the work here. srcset with w descriptors tells the browser how wide each candidate image actually is in pixels. sizes tells the browser the display intent — in this example, the image renders at 50% of the viewport on screens 60em wide and above, and 100% otherwise. The browser combines sizes with the device pixel ratio to pick the smallest candidate that satisfies the display, or the largest one if none does; it may instead use a larger candidate that is already available without a network request.

sizes is required when srcset uses w descriptors. Omitting it is a bug — the browser falls back to a default of 100vw, which overshoots whenever the image displays narrower than the viewport and makes the browser download more bytes than needed.

For fixed-size images that do not scale with the viewport — icons, avatars, badges — the x descriptor form is simpler and clearer.

html
<img
  src="avatar.jpg"
  srcset="avatar.jpg 1x, avatar-2x.jpg 2x"
  alt="..."
  width="64"
  height="64">

No sizes needed, because the display dimensions are fixed by the width and height attributes.

Art direction with picture

<picture> and <source media> solve a different problem: different crops or compositions per breakpoint. A landscape hero on wide screens becomes a square crop at medium widths and a tighter portrait crop on narrow screens, where the focal subject would otherwise get lost.

html
<picture>
  <source media="(width >= 48em)" srcset="hero-wide.jpg" width="1600" height="900">
  <source media="(width >= 30em)" srcset="hero-square.jpg" width="1000" height="1000">
  <img src="hero-portrait.jpg" alt="..." width="800" height="1200">
</picture>

The MDN <picture> reference covers the resolution algorithm — the browser walks the <source> elements in order and uses the first one whose media matches. The <img> is the fallback when no source matches, which means it doubles as the markup browsers without <picture> support fall back to. The WHATWG HTML specification's image processing algorithm documents the exact selection rules.

The mistake to avoid is reaching for <picture> when you only need different sizes of the same crop. If the composition is identical and only the pixel count changes, <img srcset + sizes> is the right primitive and <picture> is over-engineering. Art direction means different framing, not different resolution.

Format negotiation: AVIF, WebP, JPEG fallback

<picture> also handles format negotiation through <source type>. The browser picks the first source whose type it supports, so listing AVIF and WebP before the JPEG fallback lets each browser use the first of those formats it supports. A modern format is not smaller for every image — in the comparison MDN cites below, some WebP files came out larger than the reference JPEG — so measure the savings on your own content.

html
<picture>
  <source type="image/avif" srcset="photo.avif">
  <source type="image/webp" srcset="photo.webp">
  <img src="photo.jpg" alt="..." width="1200" height="800">
</picture>

The format landscape in 2026 is settled enough that the trade-offs are easy to reason about. AVIF reached Baseline 2024: Edge 121, released on January 25, 2024, was the last core browser to add support, after Chrome 85, Firefox 93 (still images; animated AVIF from Firefox 113), and Safari 16.4 on macOS (with partial support from 16.1 on macOS Ventura only) and 16.1 on iOS, per MDN's browser-compat-data. According to MDN's image format guide, AVIF generally compresses further than WebP at similar perceived quality — in the comparison MDN cites, a median of about 50 percent smaller than the source JPEG set versus about 30 percent for WebP — and it supports HDR, which WebP lacks (WebP stores 8 bits per channel). WebP reached Baseline 2020 and is the broad fallback target — most browsers in the field today support it, and Google's WebP compression study measured WebP files that were 25 to 34 percent smaller than JPEG on average at an equivalent SSIM index. JPEG is the always-works fallback that requires no negotiation.

Combining format negotiation with resolution switching is straightforward: each <source> carries its own srcset and sizes.

html
<picture>
  <source
    type="image/avif"
    srcset="photo-400.avif 400w, photo-800.avif 800w, photo-1600.avif 1600w"
    sizes="(width >= 60em) 50vw, 100vw">
  <source
    type="image/webp"
    srcset="photo-400.webp 400w, photo-800.webp 800w, photo-1600.webp 1600w"
    sizes="(width >= 60em) 50vw, 100vw">
  <img
    src="photo-800.jpg"
    srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1600.jpg 1600w"
    sizes="(width >= 60em) 50vw, 100vw"
    alt="..."
    width="1600"
    height="900">
</picture>

The markup gets verbose, but the structure is uniform. Generation is mechanical, which the build pipeline section addresses.

Lazy loading and LCP coordination

Native lazy loading and fetchpriority close the performance gap that used to require JavaScript libraries.

html
<!-- LCP image: eager + fetchpriority high, never lazy -->
<!-- Preload with fetchpriority="high" when the LCP image is referenced only from CSS or JS -->
<img
  src="hero.avif"
  alt="..."
  width="1280"
  height="720"
  fetchpriority="high">

<!-- Below-the-fold: native lazy + async decode -->
<img
  src="thumb.avif"
  alt="..."
  width="320"
  height="180"
  loading="lazy"
  decoding="async">

loading="lazy" on images reached Baseline 2022 (Safari 15.4+) and handles below-the-fold <img> elements on its own, without a JavaScript lazy-load library; the loading attribute applies only to <img> and <iframe>, so it does not lazy-load CSS background images. fetchpriority="high" reached Baseline 2024 and lets you signal to the browser that the LCP image should be fetched at a higher priority than other images. Use it on the hero image and on any image that is the LCP element; the LCP example above leaves out loading because eager is already the default. The web.dev Optimize LCP guide recommends fetchpriority="high" on an <img> that is likely to be the LCP element, notes that a high priority on more than one or two images stops helping LCP, and recommends preloading the LCP image with a high fetch priority when it is referenced only from an external CSS or JavaScript file.

Three rules apply universally. Never lazy-load the LCP image; loading="lazy" on it always adds unnecessary resource load delay and hurts LCP. Always include width and height attributes — even on responsive images — because the browser derives a default aspect ratio from those attributes and reserves layout space before the image arrives, which prevents the layout shift that would otherwise happen; pair them with height: auto in CSS, give every srcset candidate the same aspect ratio, and give art-directed <source> elements their own width and height when their crops use a different aspect ratio. Use decoding="async" on non-LCP images to signal a preference for decoding them asynchronously, so their decoding does not delay the presentation of other content.

Build pipeline: where the variants come from

Authoring eight variants of every image by hand is a non-starter. The variants come from one of three sources.

The first is a media CDN that generates derivatives on demand from URL parameters — Cloudinary, Imgix, or the media CDN baked into a headless CMS. The CMS stores the original; the CDN emits the right width, format, and quality from the request URL. This pattern suits projects with substantial media volume because content authors do not have to think about variants at all.

The second is a framework with built-in image components — Next.js's next/image, Nuxt Image's <NuxtImg> and <NuxtPicture>, Astro's <Image /> and <Picture />. These can emit srcset markup from a single source image; next/image and <NuxtImg> render an <img>, while <NuxtPicture> and Astro's <Picture /> render a <picture>. When the variants are generated depends on the framework and rendering mode: Next.js's default loader optimizes an image when it is first requested and caches the result; Nuxt Image optimizes and saves images when a static site is generated with nuxt generate (with server-side rendering disabled, it cannot do so unless the images are added as prerender routes); and Astro processes images at build time for prerendered pages and on the fly for pages rendered on demand.

The third is a hand-rolled Sharp script that emits all variants during the build. This is the right choice for projects with a small fixed image set — landing pages, marketing sites — where the build complexity of an integration is overkill. A few dozen lines of Node code generate every variant in every format.

The rule is consistent across all three: generation is mechanical, so it should be mechanical. Authoring eight <source> blocks by hand introduces bugs and creates a maintenance surface that compounds with every new image.

Decision tree

The five common cases reduce to five answers.

RequirementPrimitiveNotes
Same image, different display sizes``Use `w` descriptors and always include `sizes`.
Same image, fixed display size, multiple densities`` with `x` descriptorsAvatars, icons, badges. No `sizes` needed.
Different crops per breakpoint`` with ``Reserve for genuine art direction, not size variation.
Multiple formats with fallback`` with ``AVIF first, then WebP, then JPEG `` fallback.
Above-the-fold LCP image`fetchpriority="high"`, plus `` when the image is referenced only from CSS or JavaScript; `loading` left at its `eager` defaultNever lazy-load the LCP image.

The Responsive images and The picture element modules of web.dev's Learn Responsive Design course cover these cases with worked examples and are worth bookmarking for new developers joining the team.

Phase 1 deliverables and acceptance criteria

An audit of responsive images can start from this set of fixes.

  • Identify the LCP image on the top five routes. Add fetchpriority="high" to it, and if it is referenced only from CSS or JavaScript, add a <link rel="preload"> with fetchpriority="high" for its URL.
  • Audit every <img> for width and height attributes. Missing dimensions cause layout shift even when the image loads quickly.
  • Replace JavaScript lazy loading of below-the-fold <img> elements with native loading="lazy".
  • Add an AVIF source to <picture> blocks that already negotiate WebP. Measure the byte savings on your own photographic content before and after.
  • Verify that <picture> is used for art direction (different crops) and <img srcset> is used for resolution switching (same crop). Mixing the two is an over-engineering pattern.

The markup gets a little longer than the old <img src> pattern, but the byte count gets significantly shorter — and the maintenance surface shrinks once generation moves into the build pipeline.

Project Inquiry