Last update : July 1, 2014
Each image has an innate, original height and width that can be derived from the image data. This derived height and width information is content, not layout, and should therefore be rendered as HTML <img> element attributes. To override height and width for adaptive images, CSS is the best approach.
Context-aware images in responsive web design are created by declaring a 100% width in CSS :
img {width : 100%}
Modern browsers keep the image’s proportions intact. To render a context-aware image at its native dimensions and to resize it only if it exceeds the width of its container, the classic solution is the CSS code :
img {max-width :100%}
But scaling down images is not sufficient. Sending huge image files to low-performance devices with narrow screens is not very clever. The early HTML image tags had a lowscr attribute which is no longer supported by modern browsers.
Sending the right-sized image to devices without wasting bandwith is one of the challenges in responsive web design. The main problem is that the HTML img tag has only one source attribute today.
The different techniques proposed in the recent past by the pioneers of context-aware images, listed at the end of this post, can be grouped as follows :
- client-side current technology solutions
- server-side current technology solutions
- standardized future-technology solutions
Client-side current technology solutions :
- CSS with background-images controlled by media-queries : Harry Roberts
- dirty script to load temporary images and altering the image source path before handing it to the DOM parsing (1×1 pixel transparent GIF and <noscript> tag) : Jake Archibald, (Mairead Buchan, Antti Peisa, Vasilis van Gemert)
- dynamic modification of the base tag : Scott Jehl
- CCS3 content & attr() : Nicolas Gallagher
Server-side current technology solutions :
- php-script dealing with AJAX requests : James Fairhurst
- php-script dealing with image arrays : Craig Russel
- php-script dealing with cookies : Matt Wilcox, Keith Clark, Scott Jehl, (Mark Perkins, Andy Hume)
- service to resize images – tinySCR, now Sencha.io.SCR : James Pearce, (Graham Bird, Andrea Trasatti)
- service to adapt mobile content to cell-phones with Opera Mini pre-installed : Opera Software ASA
Standardized future-technology solutions :
- new html attribute pointing to a list of sources : Dominique Hazael-Massieux, Anselm Hannemann
- new picture tag : Bruce Lawson, Jake Archibald, Nicolas Gallagher
- progressive resolution-enhanced streaming images
- new HTTP headers for content negotiation
Problems :
“Starting with small images for mobiles and upgrade to large images for desktops, without loading both and working with all browsers” is the goal of responsive design with context-aware images. Until now there is no solution that meets this objectif.
The common problems are listed below :
- dynamic image tags : double downloads with external scripts ; race problems with internal scripts in some browsers ; inconsistencies when diffrent scripts change the base tag
- temporary image : without javascript the image never loads
- noscript tag : some browsers cannot manipulate the noscript tag
- CSS generated content : only supported in Opera10+
- cookies : no effect when cookies are disabled
- same URL : caching fails
- php scripts : CDN routing not possible
- device detection : not reliable for all browsers
Some pioneers in the field of “adaptive images” are presented hereafter :
Scripts, programs and tools :
- New Nine Media & Advertising : WordPress plugin
- Scott Jehl, Filamentgroup : javascript responsiveimgs.js
- Matt Wilcox : Adaptive Images for Responsive Designs ; http://adaptive-images.com/
- James Fairhurst : Responsive Images with PHP an jQuery
- Sencha.io : cloud platform for building mobile web apps and optimized fast image delivery
- Opera Software ASA : proxy to adapt web content provided to devices with pre-installed Opera Mini browsers
Contributions to W3C and drafts by W3C :
- RICG (Responsive Images Community Group) : Use Cases and Requirements for Standardizing Responsive Images
- Dominique Hazael-Massieux : Adaptive images
- Asbjørn Ulsberg : Adaptive Images
- Mathew Marquis : Florian’s Compromise
Blogs :
- Estelle Weyl : Clown Car Technique : Solving Adaptive Images In Responsive Web Design (61 comments)
- Christopher Schmitt : Adaptive Images for Responsive Web Design (10 likes) ; The problem with adaptive images (6 comments)
- C. Dain Miller : Adaptive images : solving the responsive image problem (20 comments)
- Jason Grigsby : Responsive Web Design Business Challenges (14 comments) — Preferred solutions for responsive images (27 comments) — Clarification on device detection for images (5 comments) — Device detection as the future friendly img option (18 comments) — Responsive IMG’s : Choosing between semantic markup and working code (5 comments) — Other mobile first responsive web design challenges (7 comments) — Responsive IMGs – Part 1 (22 comments ) — Part 2 – In-depht Look at Techniques (37 comments) — Part 3 – Future of the image tag (22 comments) — Where are the Mobile First Responsive Web Designs? (25 comments) — Weekend Reading : responsive web design and mobile context (3 responses)
- Keith Clark : Responsive images using cookies (30 comments)
- Bruce Lawson : Notes on Adaptive Images (yet again!) (79 comments) ; Adaptive images : end of round one (61 comments) ; Responsive images – interim report (20 comments)
- Ethan Marcotte : Fluid images (50 comments)
- Chris Coyier : Techniques for Context Specific Images (37 comments) ; Which responsive images solution should you use? (39 comments)
- Robert Nyman : Discussing alternatives for various sizes of the same image & introducing src property in CSS as an option (44 comments)
- Jake Archibald : Adaptive Images for Responsive Designs… Again (31 comments)
- Harry Roberts : Responsive images right now (29 comments)
- Yoav Weiss : Simpler responsive images proposal (5 comments) — Preloaders, cookies and race conditions (9 comments) — Simpler responsive images proposal (5 comments) — Responsive images – hacks won’t cut it (8 comments) — My take on adaptive images (9 comments)
- Scott Jehl : Responsive Images: Experimenting with Context-Aware Image Sizing (25 comments)
- James Pearce : First, Understand your Screen (85 comments)
- Craig Russel : Responsive Images and Context Aware Image Sizing (18 comments)
- Mairead Buchan : Creating responsive images using the noscript tag (112 comments)
- Nicolas Gallagher : Responsive images using CSS3 (6 comments)
- Tim Wright : Picturefill 2.0: Responsive Images And The Perfect Polyfill (46 comments)
- Eric Portis : Responsive Images Done Right: A Guide To And srcset (31 comments)
more contributors :
- Graham Bird (Doubletake.js)
- Vasilis van Gemert
- Andy Hume
- Antti Peisa
- Mark Perkins
- Andrea Trasatti