How can you serve images suited to different browsers and viewport sizes?

ProcrustesPR

To serve images suited to different browsers and viewport sizes, address format compatibility and display dimensions separately: use picture to provide multiple formats and a fallback image, then use srcset to list images at different sizes and sizes to describe the expected display width. If you need to limit downloads of large images on small viewports, you can also add media conditions. Image selection must account not only for screen size, but also for the image’s layout container and device pixel ratio (DPR).

ProcrustesPRProcrustesPRHow Should a CMS Handle Images? From Upload Optimization to Descriptions and URL Management

Use picture to order formats and keep a fallback image

The web.dev example uses source elements within picture to offer AVIF followed by WebP, with an img element providing a JPEG fallback. The browser checks them in order and uses a format it can decode when the conditions match. If it does not support an earlier format, it continues to the next one. This avoids relying on every browser to support the same new format.

  • The source element’s type identifies the image format, while srcset provides candidate images.
  • A picture element must still contain an img element, not just source elements.
  • Set alt, width, and height on img; they apply regardless of which source is selected.

Use density descriptors for fixed display dimensions and sizes for flexible layouts

If an image is always displayed at a width of 500 CSS pixels across different viewports, you can provide images 500, 1000, and 1500 pixels wide, labeled as 1x, 2x, and 3x candidates, respectively. This lets the browser choose based on pixel density and other conditions. But if the container scales with the viewport, these density descriptors alone cannot describe the layout.

In that case, use width descriptors such as 500w, 1000w, and 1500w in srcset, together with sizes. 1000w means the image file itself is 1000 pixels wide; it does not require the image to be displayed at a width of 1000 pixels. The sizes attribute describes the expected display width in CSS pixels—for example, 500 pixels when the viewport is at least 768 pixels wide, and the full viewport width when it is narrower.

For example, an image filling a viewport 320 CSS pixels wide on a device with a DPR of 3 would need approximately 960 device pixels, making 1000w a close match. This illustrates the basis for image selection; it does not mean every browser will always download the same file under all conditions.

Use separate conditions to limit large-image downloads on small viewports

Even on a small screen, the browser may select a large image if the DPR is high. To limit this, you can group candidates using media conditions in picture. For example, when the viewport is no wider than 560 pixels, offer only candidates that are 500 and 1000 pixels wide. Even with a DPR of 3, the browser cannot select an image 1500 pixels wide from that group. The media attribute specifies conditions the browser must follow, while srcset provides hints for image selection.

Another approach is to offer more heavily compressed versions when images are displayed at small sizes on high-density screens, while retaining the original quality on desktop. Compression artifacts are less noticeable under these conditions, but you should still compare the actual results. More candidates are not necessarily better: each additional size or format adds management costs and may reduce cache efficiency.

ProcrustesPRProcrustesPRHow should images of different sizes on the same website be named?

Images for different browsers and viewport sizes: perspectives from across the web

When is it worth preloading images that vary with the viewport?

Preloading is most worth considering when an image is a critical resource the browser discovers relatively late, such as a CSS background image that may become a Largest Contentful Paint (LCP) candidate, or an LCP image loaded by JavaScript. If you are preloading an image displayed by an img element and the image varies with the viewport, web.dev recommends adding imagesrcset, omitting src, and setting fetchpriority="high". Preloading alone does not raise the image's priority.

Can an image CDN help handle browser differences?

Yes. An image CDN can optimize images for the user's device and browser and serve an appropriate format. However, web.dev cautions that more candidate versions are not necessarily better: too many versions increase costs and reduce browser cache efficiency. Keep the number of candidate images manageable, then measure their impact on the user experience.

Why is it still worth providing a fallback URL in img's src?

Besides supporting browser compatibility, a fallback URL helps some crawlers find images. A 2026 report citing Google's documentation notes that Search can still find the image referenced by an img element's src even when the img is inside picture. The documentation recommends providing a fallback URL because some browsers and crawlers do not support or cannot read picture or srcset.

ProcrustesPRHow many image variants should you prepare, and how should you manage them?

References

  1. Assist the browser with resource hintsweb.dev — Discusses: When is it worth preloading images that vary with the viewport?
  2. Image performanceweb.dev — Discusses: Can an image CDN help handle browser differences?
  3. Google Images & Discover Previews Don’t Support JPEG XLwww.searchenginejournal.com · 2026-10-21T13:00:00+00:00 — Discusses: Why is it still worth providing a fallback URL in img's src?

Related articles

How Should a CMS Handle Images? From Upload Optimization to Descriptions and URL ManagementHow should images of different sizes on the same website be named?How many image variants should you prepare, and how should you manage them?How do visual and short-form video trends in search results affect SEO?How can photography websites use SEO to increase visibility and attract clients?How can service and e-commerce websites improve search visibility? Start by distinguishing local needs from buying intentWhy optimize a website, and which tasks can be done for free?How can you use search results page features to attract traffic?
ProcrustesPR
ProcrustesPR