Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

srcset

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 srcset attribute 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.

Values

A comma-separated list of candidates. Each is a URL followed by at most one descriptor.

DescriptorExampleMeaning
Width wphoto-800.jpg 800wThe file is 800 pixels wide. Needs sizes.
Density x[email protected] 2xFor screens with this device pixel ratio.
Nonelogo.pngSame as 1x.

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 valueMeaning
Media conditions and lengths, e.g. (min-width: 48rem) 50vw, 100vwThe first matching condition gives the slot width; the last entry has no condition.
autoLazy images only: the browser uses the image's laid-out width. Write auto, 100vw to give older browsers a fallback.
Absent100vw. 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.

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.

Art direction with picture

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).

Format fallback

In Vanilla Breeze

  • 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

Which to choose

  • srcset + sizes="auto" — lazy images below the fold. No hand-written sizes.
  • srcset + hand-written sizes — the LCP image and other eager images, when you know the layout widths.
  • data-responsive — eager images whose width you do not want to hard-code, or to generate srcset from a list of widths.
  • <picture> — different crops or formats.
↑