Welcome to Vanilla Breeze
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
Responsive images: provide multiple image sources for different screen sizes and pixel densities. Works with sizes for resolution switching and picture for art direction.
The srcset attribute lets you provide multiple image files at different sizes or resolutions so the browser can pick the best one for the current viewport and device pixel ratio. It replaces the old pattern of serving a single oversized image to every device.
There are two approaches: width descriptors (with the sizes attribute) for resolution switching, and density descriptors for fixed-size images at different pixel ratios. For entirely different crops at different breakpoints, use the <picture> element for art direction.
Applies to: <img>, <source> (inside <picture>)
| Descriptor | Syntax | Use Case |
|---|---|---|
Width (w) | photo-800.jpg 800w | Browser picks based on viewport width + sizes |
Density (x) | [email protected] 2x | Fixed-size images at different pixel ratios (icons, logos) |
You cannot mix w and x descriptors in the same srcset.
For content images that scale with the layout, use width descriptors. The sizes attribute tells the browser how wide the image will render at each breakpoint, so it can calculate which file to download before CSS is parsed.
<!-- Width descriptors: browser picks the best file based on viewport --><img src="photo-400.jpg" srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1200.jpg 1200w" sizes="(min-width: 768px) 50vw, 100vw" alt="Landscape photo" />
The sizes value (min-width: 768px) 50vw, 100vw means: above 768px the image occupies 50% of the viewport; below that, 100%. The browser multiplies this by the device pixel ratio to pick a file.
Using srcset with width descriptors but omitting sizes causes the browser to assume sizes="100vw". On a page where the image is only 50% wide, the browser downloads a file twice as large as needed.
For fixed-size images (logos, icons, avatars), density descriptors are simpler. The browser matches the descriptor to the device pixel ratio.
<!-- Density descriptors: match device pixel ratio --><img src="logo.png" srcset="logo.png 1x, [email protected] 2x, [email protected] 3x" alt="Company logo" />
When you need different crops or aspect ratios at different breakpoints (not just different resolutions of the same image), use <picture> with <source media="..."> elements. The browser picks the first <source> whose media query matches.
<!-- Art direction: different crops for different breakpoints --><picture> <source media="(min-width: 1024px)" srcset="hero-wide-800.jpg 800w, hero-wide-1600.jpg 1600w" sizes="100vw" /> <source media="(min-width: 640px)" srcset="hero-medium-600.jpg 600w, hero-medium-1200.jpg 1200w" sizes="100vw" /> <img src="hero-narrow-400.jpg" srcset="hero-narrow-400.jpg 400w, hero-narrow-800.jpg 800w" sizes="100vw" alt="Mountain landscape" /></picture>
Combine <picture> with type to serve modern formats (AVIF, WebP) with JPEG fallback. The browser picks the first format it supports.
<!-- Modern formats with fallback --><picture> <source type="image/avif" srcset="photo-400.avif 400w, photo-800.avif 800w" /> <source type="image/webp" srcset="photo-400.webp 400w, photo-800.webp 800w" /> <img src="photo-400.jpg" srcset="photo-400.jpg 400w, photo-800.jpg 800w" sizes="(min-width: 768px) 50vw, 100vw" alt="Vacation photo" /></picture>
alt attribute is still required on the <img> element. It applies regardless of which source the browser selects.srcset does not work on CSS background-image. Use image-set() in CSS for similar resolution switching.sizes values. If your layout changes via CSS later, the sizes may become stale.