Responsive images

Back to the index.

Responsive images consist of four possible syntaxes: an <img> tag with srcset x or w, or a <picture> tag with media queries or file type sources.

The problem on desktop is that it is possible to change the DPR in most browsers by zooming, and the layout viewport width by either zooming or resizing. None of these problems occur on mobile.

This is the desktop table. The mobile table isn’t ready yet.

Last updated on 18 April 2016.

ALL ENTRIES ARE STILL UNDER CONSIDERATION; THIS IS A TEST.

Compatibility

<img>

Desktop responsive <img> tags are in chaos; especially with img-w. Browsers pretty much do as they please. My general advice is to use the <picture> element if predictable desktop behaviour with zoom and/or resize is important to you.

Method or property Internet Explorer Edge 13 Firefox Safari Chrome Opera
8 9 10 11 45 Win 45 Mac 45 Linux 9.0.2 49 Win 49 Mac 36 Win 36 Mac
srcset x
Test page
No Almost Yes Alternative Static and persistent

Firefox and Safari are straightforward and logical. In Firefox the image is changed whenever the DPR value changes (i.e. when the user zooms). Safari treats DPR as a constant and therefore never changes the image. Their behaviour is thus consistent with their treatment of DPR.

In Edge the image is adjusted when you zoom in, but not when you zoom out. Reloading the page restores the correct image in all cases.

In Chrome and Opera the image is not adjusted when you zoom; only when you reload. HOWEVER, a reload will always cause the highest-density image in your cache to be displayed, even if the current DPR calls for a lower-density one.

srcset w and sizes
Test page
No Wrong Almost Static Wrong

General note: browsers are allowed to do as they please with img-w. Thus any and all bugs below can be defended by “It’s how we choose to do it.” Whether that makes img-w a useful tool is unclear.

Firefox adjusts the image when you resize and zoom, but it has issues at very high or very low zoom levels: although the image size is adjusted correctly, the the image source is not. I haven’t been able to figure out what’s going on.

Safari picks the correct image when the page loads, but does not adjust it to zoom or resize.

In Edge the image is adjusted when you resize the window to make it larger, but not when you make it smaller. Its reaction to zooming is confused, and I don’t understand it. Reloading the page gives the correct image when you’ve resized, but the zooming problems persist.

Chrome and Opera, finally, oh my! Zooming and resizing change the image size, but not necessarily its source. Zooming does nothing to the source. Resizing to make the window larger changes the source; smaller does not. (This is the same as Edge). Finally, when you reload the page you get the largest image that’s currently in the cache.
Unlike with img-x, where retaining the highest-density image makes some sort of sense, retaining the largest image with img-w does not make sense at all. It could be than a smaller image is better suited to the current zoom level or window width, and Chrome ignores that.

In general I advise you to use the picture element instead, even though it doesn’t work in Safari.

currentSrc
See previous test pages
No Yes Yes No Yes
img.currentSrc

The source that’s currently being applied to the image. May change with zooming.

Method or property Internet Explorer Edge 13 Firefox Safari Chrome Opera
8 9 10 11 45 Win 45 Mac 45 Linux 9.0.2 49 Win 49 Mac 36 Win 36 Mac

<picture>

The <picture> element is a safe haven of stability and predictability. The only problem is that it’s not supported in Safari.

Method or property Internet Explorer Edge 13 Firefox Safari Chrome Opera
8 9 10 11 45 Win 45 Mac 45 Linux 9.0.2 49 Win 49 Mac 36 Win 36 Mac
source + media queries
Test page
No Yes Yes No Yes

All browsers handle zooming and resizing correctly.

image formats
Test page
No Yes Yes No Yes
currentSrc
See previous test pages
No Yes Yes No Yes
picture.querySelector('img').currentSrc

The source that’s currently being applied to the image. May change with zooming. Note that this is a property of the <img> tag, not the <picture> tag.

Method or property Internet Explorer Edge 13 Firefox Safari Chrome Opera
8 9 10 11 45 Win 45 Mac 45 Linux 9.0.2 49 Win 49 Mac 36 Win 36 Mac

Tested browsers

Desktop browser test array 2.2; February 2016

IE 8, 9, and 10
Trident
On separate Windows 7 virtualizations as downloaded from Modern IE.
IE11
Trident
On Windows 8.1 virtualization as downloaded from Modern IE.
On Surface
Edge 13
MS Edge 13
On Windows 10 virtualization as downloaded from Modern IE.
Firefox
Gecko 45
45 on Win7, Mac and Linux
Safari
WebKit
9.0.2 on Mac
Chrome
Chromium 49
49 on Win7 and Mac
Opera 36
Chromium 49
36 on Win7 and Mac

Operating systems

Mac
MacBook Pro 17'' with OS 10.9.4
This is my main test station. It also runs all virtual Windows systems.
Windows
All downloaded from modern.ie. I use VirtualBox, and downloded the Windows 7 systems for all browsers but IE11, which runs on Windows 8.1.
The non-IE Windows browsers all run on the IE9/Win7 virtualization.
Surface
Microsoft Surface with Windows RT 8.1
Linux
Ubuntu 12.04 on pretty old hardware. Not fair for performance comparisons.