What are Adaptive Images?
Adaptive images are asset variants selected or generated for a viewer’s display size, pixel density, format support, or network conditions. Each variant represents the same source at a suitable delivery profile.
How Adaptive Images work
Adaptive image delivery keeps one source and offers several variants that differ in pixel width, pixel density, crop, or encoding format. The HTML Standard discusses the technique under the heading “Adaptive images”; MDN calls it responsive images. The variant can be chosen in two places. In markup, srcset and sizes list candidates and the browser picks one, while picture with source elements adds rules for art direction (media) and for format (type). On the server, a single URL returns different bytes depending on request headers such as Accept or client hints. Markup-based selection needs only a distinct URL per variant. Server-side selection keeps the HTML short but makes correct results depend on how caches are told about the varying headers.
Key facts
- Why does a small image on the page still download the largest file? The browser starts fetching images before it has applied the page’s CSS, so the layout width has to be declared in HTML. With
wdescriptors the HTML Standard requires asizesattribute; if it is missing or cannot be parsed, the width is taken as100vw, as if the image filled the viewport. Eachwvalue must also match the file’s real pixel width. On images withloading="lazy",sizes="auto"lets the browser use the rendered width, with a fallback list after it for browsers that do not support the keyword. Only before such animgmaysourceelements leavesizesout, which the standard treats as equivalent toauto. - Can I predict exactly which candidate a browser loads? Not from
srcsetalone. The standard lets the browser choose “in an implementation-defined manner” and weigh pixel density, zoom level, and possibly network conditions, so two browsers may load different files from the same markup. Choosing betweensourceelements is rule-based instead: the browser takes them in order and uses the first one whosemediaquery matches and whosetypeit supports, treating a missing attribute as a pass. Reservemediafor art direction, where a different crop must be shown, and let the browser decide between resolutions. - How do I offer AVIF or WebP with a fallback? Put one
sourceper format insidepicture, each with atypeattribute such astype="image/webp", followed by animgin a widely supported format. The browser skips anysourcewhose type it does not support. Do not omittype: without it, the HTML Standard says the browser will not move on to anothersourceafter fetching an image format it does not support. When a crop is also selected withmedia, give that crop asourcein the fallback format too and place its sources before those that apply more broadly; otherwise a browser that cannot decode the newer format falls through to a different crop. - What changes when the server picks the variant instead? Caches must know which request headers the choice depended on. A response selected by
Acceptor by a client hint should list that header inVary; otherwise a cache may reuse one variant for a request that needed another. Hints such asSec-CH-Widthare sent only after the server opts in withAccept-CH, and MDN marksSec-CH-Widthas experimental, so check browser support and keep a sensible default for requests that carry no hints.
When Adaptive Images matter
Serve smaller variants to narrow screens while retaining denser versions for high-density displays. Incorrect sizing rules can waste bandwidth or leave an image visibly soft at its rendered dimensions.
How Transloadit helps with Adaptive Images
Transloadit’s Smart CDN can create the variants on request. A tlcdn.com URL names your Workspace, a Template, and the source file, and URL parameters such as a width fill Template variables that configure Robots like /image/resize. A request that misses the cache runs the Template; requests that hit the cache reuse the stored result. Choosing which URL a visitor loads stays in your markup: the pages linked here describe variants addressed by URL parameters and do not describe selection from request headers such as Accept, so list the variant URLs in srcset or picture.
Every cache miss imports and transforms the file and counts toward usage: the first request for each new parameter combination, and any later request made once the cached copy is no longer available, which depends on your caching settings. Cache hits are not transformed again. Limit the variables a Template accepts and sign Smart CDN URLs so that visitors cannot request arbitrary variants. When every size is known before publication, running an Assembly once and serving its stored outputs avoids on-demand transformation.
Sources
- HTML Standard: Images (adaptive images, srcset and sizes attributes, selecting an image source)
- HTML Standard: the picture, source, and img elements
- MDN: Responsive images
- WHATWG HTML issue #4654: “auto sizes” for lazy-loaded images
- RFC 9110: HTTP Semantics, section 12.5.5 Vary
- MDN: HTTP Client hints
- MDN: Sec-CH-Width header