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…
The picture element enables art direction and format switching by providing multiple image sources for different screen sizes and browser capabilities.
Description
The <picture> element is a container for zero or more <source> elements and one <img> element. It allows the browser to choose the most appropriate image source based on media queries, image format support, or pixel density.
Vanilla Breeze styles <picture> as a block-level element. The contained <img> keeps the standard image rule (max-inline-size: 100%): it shrinks to fit the picture but is never upscaled past its intrinsic width, so small sources stay sharp. Add class="full" to the <picture> (or the <img>) to stretch it to the full width. Inside a [data-media] ratio box, the image fills the box and crops to fit.
When to Use
Art direction - Different image crops for different viewport sizes (e.g., landscape hero on desktop, portrait on mobile)
Format switching - Serve modern formats (WebP, AVIF) with fallbacks for older browsers
Resolution switching - Serve different resolutions based on device pixel ratio
Dark mode images - Different images for light and dark color schemes
When to Use img Instead
Single image that works well at all sizes - use <img> with srcset and sizes
Simple responsive images where only resolution changes - <img srcset> is sufficient
Decorative images - CSS background images may be more appropriate
Live Examples
Art direction, format switching, and image variants applied through the <picture> element.
Art Direction
Serve different image crops based on viewport width using media queries on <source> elements.
The browser evaluates <source> elements from top to bottom and uses the first one with a matching media condition. The <img> serves as the fallback.
Format Switching
Serve modern image formats to browsers that support them while providing fallbacks for others.
Format switching with picture
12345678910
<picture><!-- AVIF: best compression, growing support --><sourcetype="image/avif"srcset="photo.avif" /><!-- WebP: good compression, wide support --><sourcetype="image/webp"srcset="photo.webp" /><!-- JPEG: universal fallback --><imgsrc="photo.jpg"alt="A beautiful photograph" /></picture>
Format
MIME Type
Best For
AVIF
image/avif
Best compression, photos and illustrations
WebP
image/webp
Good compression, wide browser support
JPEG
image/jpeg
Photos, universal compatibility
PNG
image/png
Transparency, sharp edges, screenshots
Dark Mode Images
Serve different images based on the user's color scheme preference.
Dark mode image switching
1234567
<picture><!-- Dark mode version --><sourcemedia="(prefers-color-scheme: dark)"srcset="logo-dark.png" /><!-- Light mode version (fallback) --><imgsrc="logo-light.png"alt="Company logo" /></picture>
This technique is especially useful for logos, diagrams, and illustrations that need different color treatments for light and dark themes.
Combined Techniques
Combine art direction, format switching, and resolution switching for optimal delivery.
Apply variant classes to the inner <img> element, not the <picture>. All <img> variant classes (.rounded, .circle, .thumbnail, etc.) work inside <picture>.
The altattribute goes on the <img> element, not <picture>
All source variations should convey the same information (art direction changes framing, not content)
Screen readers announce the <img> - the <picture> wrapper is transparent
Don't use <picture> to hide content from some users
Accessible picture element
12345
<!-- Correct: alt on img --><picture><sourcesrcset="hero-wide.jpg"media="(min-width: 800px)" /><imgsrc="hero-mobile.jpg"alt="Team members collaborating around a table" /></picture>
Related
<img> - Required child element that receives the final image
<source> - Define alternative image sources with media/type conditions
<figure> - Wrap picture elements that need captions
<compare-surface> - Before/after image comparison slider for showcasing image differences