<picture> patterns

A collection of code patterns and demonstrations using srcset combined with the HTML <img> and <picture> elements

Icon The basics

This is a rough outline of what will be in this section:

This project is a work in progress. The basics, more examples and resources will be added soon along with Picturefill-ed versions of each example. Browser support also needs updating and testing, including Safari 9.1 / iOS 9.3 now that it supports the full spec.


Icon <img> and resolution changing

Using srcset -x to swap resolution
Source image is picked based on screen density. Good for fixed-width images and not much else.
Using srcset -w to pick the best size
Source image is picked intelligently based on available widths, screen density and display size.
Using srcset -w to pick the best size, and the image changes size across breakpoints
Source image is picked intelligently based on available widths, screen density and display size.
Testing srcset -w syntax, when no source attribute is set
A stress test for browsers in how they handle this non-spec situation.

Icon <picture> and art direction

Using -x syntax to set density
Allow different sources with density support.
Using -w syntax to set density
Allow the browser to more intelligently pick the best source based on available widths, screen density and display size at each breakpoint.
Simple art direction changes
When images need to either display differently cropped sources, or change aspect across breakpoints, art direction is needed.
Complex art direction with -x syntax
Using -x syntax to enforce explicit source selection with complex image elements, changing aspect and scale multiple times.
Complex art direction with -w syntax
Using -w syntax to allow permissive source selection with complex image elements, changing aspect and scale multiple times.

Icon Other examples

Using <picture> to choose the best image format types
Provide different formats based on browser support, with fallbacks provided.