Configuring image styles for optimized deliveryfor Drupal 11 , 10 , 9 , and 8

Last updated :  

Serving a phone the same 3000px-wide image you serve a desktop monitor wastes bandwidth on every mobile visit — often the majority of your traffic. Responsive image styles let Drupal generate several sizes of the same image up front and hand the browser a menu to choose from, so each device downloads only what it actually needs.

What you'll learn in this lesson

  • The relationship between image styles, breakpoints, and responsive image styles — three related but distinct pieces
  • How the generated <picture>/srcset markup lets the browser pick the right file
  • Why derivatives are generated on first request, not in advance

Three pieces, one system

These three admin pages work together and are easy to mix up:

  • Image styles (/admin/config/media/image-styles) — define individual crop/resize/scale effects, e.g. "Thumbnail (300×200)" or "Hero (1600×900)."
  • Breakpoints — defined by your theme's *.breakpoints.yml file, describing viewport width ranges (mobile/tablet/desktop).
  • Responsive image styles (/admin/config/media/responsive-image-style) — map each breakpoint to one or more image styles, e.g. "use the 400px-wide style below 600px viewport width, the 1600px-wide style above it."

What gets rendered

Once a field's formatter is set to a responsive image style, Drupal renders a real <picture> element:

<picture>
  <source srcset="/files/styles/mobile/photo.jpg" media="(max-width: 600px)">
  <source srcset="/files/styles/desktop/photo.jpg" media="(min-width: 601px)">
  <img src="/files/styles/desktop/photo.jpg" alt="A description">
</picture>

The browser itself decides which <source> matches its current viewport and only downloads that one file — the others are never fetched.

Image style derivatives are generated lazily, not when you save the image style configuration. The very first request for a given (image, style) combination triggers Drupal to actually resize/crop the file and cache the result to public://styles/<style>/...; every later request for that same derivative is served straight from that cached file. This means the first visitor to load a page with a brand-new image style will see a very slightly slower first load while the derivative is generated — expected behavior, not a bug.

See it for yourself

Set an image field's formatter to a Responsive Image style at Manage display, save, then view the rendered page's source — you'll see a real <picture> element with multiple <source> tags instead of a single <img>.

Quick check: you created a new image style and set it as part of a responsive image style, but the very first page load after saving felt slightly slow, then was fast on every reload after. Bug or expected? (Expected — that first request triggered the actual on-disk derivative generation, which is then cached for every subsequent request.)

Key takeaways

  • Image styles, breakpoints, and responsive image styles are three separate but connected pieces — the responsive image style is what ties a breakpoint to a specific image style.
  • Responsive image styles render as real <picture>/<source> markup, letting the browser itself choose which file to download.
  • Image derivatives are generated on first request and cached to public://styles/ — not pre-generated when you save configuration.

Coming up next

Images aren't the only render-blocking asset worth a second look — web fonts have their own loading quirks. Next: Optimizing Font Loading.