0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Offer several image files so the browser picks the right one for the layout width and pixel density. Covers sizes, sizes=auto, picture and VB's data-responsive.
Overview
The srcsetattribute lists candidate image files so the browser can download the one that suits the rendered size and the screen's pixel density, instead of sending every device the largest file.
There are two kinds of candidate. Width descriptors (800w), together with sizes, are for images that change size with the layout. Density descriptors (2x) are for images shown at a fixed size. For a different crop at different breakpoints, use <picture> with <source media> (art direction).
Applies to:<img>, and <source> inside <picture>. Its partner sizes applies to the same elements.
Width descriptors with sizes
12345
<imgsrc="photo-800.jpg"srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1200.jpg 1200w"sizes="(min-width: 48rem) 50vw, 100vw"width="1200"height="600"alt="Harbour at dusk with fishing boats moored along the quay">
Values
A comma-separated list of candidates. Each is a URL followed by at most one descriptor.
Do not mix w and x in one list. src stays the fallback for browsers that ignore srcset. With density descriptors it also counts as the 1x candidate when the list has none.
sizes value
Meaning
Media conditions and lengths, e.g. (min-width: 48rem) 50vw, 100vw
The first matching condition gives the slot width; the last entry has no condition.
auto
Lazy images only: the browser uses the image's laid-out width. Write auto, 100vw to give older browsers a fallback.
Absent
100vw. The spec requires sizes whenever srcset uses w descriptors.
Examples
sizes="auto" for lazy images
Writing sizes by hand means repeating your CSS layout in the markup, and it goes stale. A lazy image is laid out before it is fetched, so the browser can measure it instead. sizes="auto" only works together with loading="lazy"; on an eager image it is ignored and the fallback after the comma applies.
Measured sizes for a lazy image
12345
<imgloading="lazy"sizes="auto, 100vw"src="card-400.jpg"srcset="card-400.jpg 400w, card-800.jpg 800w, card-1200.jpg 1200w"width="1200"height="800"alt="Trail runner crossing a stream on a forest path">
Give the image width and height (or a CSS size): an image that is 0×0 before it loads measures as 0.
Density descriptors
For logos, icons and avatars shown at a fixed CSS size.
When small screens need a different crop, not just a smaller file, use <source media>. The browser takes the first matching source. Give each source its own width and height when the crops have different aspect ratios, so the right box is reserved (Chrome 90, Firefox 108, Safari 15).
Different crops per breakpoint
123456789
<picture><sourcemedia="(min-width: 64rem)"srcset="hero-wide-1600.jpg 1600w, hero-wide-2400.jpg 2400w"sizes="100vw"width="2400"height="900"><imgsrc="hero-square-800.jpg"srcset="hero-square-800.jpg 800w, hero-square-1200.jpg 1200w"sizes="100vw"width="1200"height="1200"alt="Climbers on a ridge above the clouds"></picture>
data-responsive (src/utils/responsive-init.js, src/utils/responsive.css) measures an image's rendered width and writes it to sizes, which is useful for eager images where sizes="auto" is not allowed. Given a list of widths (data-responsive="400,800,1200") it generates srcset from the src file name. An authored srcset wins, and an authored sizes="auto" on a lazy image is left to the browser. data-responsive-debug adds a badge naming the chosen file, read from img.currentSrc.
Image defaults.src/native-elements/image/styles.css makes every <img>max-inline-size: 100%; block-size: auto; display: block, so the width and height attributes set the aspect ratio without fixing the size.
Placeholders. VB's demos use local SVG placeholders in src/assets/placeholders/; the responsive-400/800/1200.svg set prints its own width, which makes srcset choices visible. data-mock generates placeholders in prototypes.
Accessibility
The alt on the <img> applies to whichever candidate loads. Describe the content, not the file.
If an art-directed crop drops something the alt mentions, rewrite the alt so it is true for every crop.
Browser support
srcset, sizes and <picture> work in all current browsers. sizes="auto": Chrome 126, Firefox 150, Safari 27 (partial: SVG images with object-fit are distorted), as of November 2026.
Gotchas
w descriptors without sizes mean 100vw. An image in a half-width column then downloads a file twice as wide as it needs.
The choice is the browser's. It may reuse a larger file it already has in cache, or pick a smaller one on a slow connection. You cannot set it from script, but img.currentSrc tells you what it chose.
srcset does not apply to CSS backgrounds. Use image-set() there.
Hand-written sizes go stale when the CSS layout changes. Prefer sizes="auto" on lazy images, or data-responsive.
Related
loading — lazy loading, fetchpriority and decoding; needed for sizes="auto".