Images (co)respond to the environment.
Device pixel ratio is the ratio between CSS pixels and physical pixels.
<picture>
ElementPicture 95
<picture> <!-- This source element covers the range 320-400, so the midpoint is 360, and that's what I'm using to calculate the x values, e.g. 320/360=0.89; similarly below --> <source media="(max-width: 400px)" srcset="160.jpg 0.44x, 320.jpg 0.89x, 480.jpg 1.33x, 640.jpg 1.78x, 960.jpg 2.67x"> <source media="(max-width: 520px)" srcset="160.jpg 0.35x, 320.jpg 0.7x, 480.jpg 1.04x, 640.jpg 1.39x, 960.jpg 2.09x, 1280.jpg 2.78x"> <source media="(max-width: 639px)" srcset="320.jpg 0.55x, 480.jpg 0.83x, 640.jpg 1.1x, 960.jpg 1.66x, 1280 2.2x, 1920 3.31x"> <!-- Note that in the next 2 source elements, images are only half the viewport width --> <source media="(max-width: 800px)" srcset="160.jpg 0.44x, 320.jpg 0.89x, 480.jpg 1.33x, 640.jpg 1.78x, 960.jpg 2.67x"> <source media="(max-width: 959px)" srcset="160.jpg 0.36x, 320.jpg 0.73x, 480.jpg 1.09x, 640.jpg 1.45x, 960.jpg 2.18x, 1280.jpg 2.91x"> <!-- And in the next 4, images are only 1/3 of the viewport width --> <source media="(max-width: 1200px)" srcset="160.jpg 0.44x, 320.jpg 0.89x, 480.jpg 1.33x, 640.jpg 1.78x, 960.jpg 2.67x"> <source media="(max-width: 1440px)" srcset="160.jpg 0.36x, 320.jpg 0.73x, 480.jpg 1.09x, 640.jpg 1.45x, 960.jpg 2.18x, 1280.jpg 2.91x"> <source media="(max-width: 1920px)" srcset="320.jpg 0.57x, 480.jpg 0.86x, 640.jpg 1.14x, 960.jpg 1.71x, 1280 2.29x, 1920 3.43x"> <!-- This covers the range 1920-2560, but I left off the upper bound so any truly huge monitors get sensible behaviour --> <source srcset="320.jpg 0.43x, 480.jpg 0.64x, 640.jpg 0.86x, 960.jpg 1.29x, 1280 1.71x, 1920 2.57x"> </picture>
Press ctr+alt+del to reset standardization.
srcset
attribute
<img alt="The Breakfast Combo"
src="banner"
srcset="banner-HD 2x,
banner-phone 100w,
banner-phone-HD 100w 2x">
<img src="some/image">
Vary:
It's all pretty much $#@%!.
<picture alt="..." width="" height="" src="small.jpg"> <source media="(min-width: 600px)" srcset="medium-1.jpg 1x, medium-2.jpg 2x"> <source media="(min-width: 1000px)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <img src="small.jpg" alt="why is it so difficult?"> </picture>
<img src="pic-small.jpg" alt="..."
src-1="(min-width: 400px) pic-medium.jpg"
src-2="(min-width: 1000px) pic-large.jpg">
<src-n-attribute> = <media-query>? [ <x-based-urls> | <viewport-urls> ]
<img src-1="
100%;
pic1.png 160, pic2.png 320, pic3.png 640, pic4.png 1280, pic5.png 2560
">
100 30em 400 70em 50%;
<img src-1="
100 30em 400 70em 50%;
pic50.png 50, pic100.png 100, pic200.png 200,
pic400.png 400, pic800.png 800, pic1600.png 1600,
pic3200.png 3200">
If the browser knows everything...
(8kb)
200x200
400x288
770x512