The A List Apart Blog Presents:

Article Update: Don’t Rely on Default `sizes`

Article Continues Below

In “Responsive Images in Practice” I made no little hay that sizes was optional—leave it off, and browsers will substitute the default value: 100vw.

That last part is still true: browsers will still use 100vw as a last resort. While the sizes-less examples in the article still function, they no longer validate. The spec has changed, and sizes is no longer optional when using srcset and w descriptors.

validation error image

Why?

Too many people were relying on the invisible default for images whose display size wasn’t even close to 100vw, resulting in inappropriate srcset selections and wasted bytes. Developers learning the new markup were also getting tripped up on how sizes affects intrinsic sizing. Absent any CSS to the contrary…

<img srcset="image.jpg 320w" />

…always displays at the full viewport width. If you don’t know about the 100vw default (and especially if you’re a little fuzzy on what intrinsic sizing is, or how sizes affects it), that’s pretty surprising.

By requiring that authors explicitly state (and with any luck, think about) a sizes value whenever they use w descriptors, the spec eliminates reliance on the invisible 100vw default. This will hopefully cut down on mistakes; at a bare minimum, it ensures that incorrect values are visible. So carry on, and if you want your markup to be valid, easier to debug, and easier to understand—don’t forget the sizes.

2 Reader Comments

  1. Hi Eric,
    what I am still missing from the whole responsive images discussion. If I have a “stage teaser” (or however you call it in English) like here:
    http://praxisklinik-ahnefeld.de/ (The photo of the two doctors, stretching across the whole screen)

    What are the exact and best images sizes and responsive techniques for that? (That site simply loads the biggest quality picture, even for the mobile version…)

  2. Really nice article…. Quite knowledgeable … Thanks for sharing information. I have become habitual to read your knowledgeable articles. Keep it up.

Got something to say?

We have turned off comments, but you can see what folks had to say before we did so.

More from ALA

Design for Amiability: Lessons from Vienna

Computing was born in a Viennese café. Between 1928 and 1934, while Hitler plotted and Europe crumbled, a motley crew of mathematicians, philosophers, architects, and economists gathered weekly to puzzle out the limits of reason—and invented Computer Science in the process. What made their collaboration possible wasn't just brilliance (though they had plenty). It was amiability: the careful design of a social space where difficult people could disagree without destroying each other. Longtime A List Apart contributing author Mark Bernstein mines this forgotten history for lessons that might just save today's embattled web from its worst impulses. Spoiler: it involves better coffee service and the looming threat of public humiliation.

From Beta to Bedrock: Build Products that Stick.

Building towards bedrock means sacrificing some short-term growth potential in favour of long-term stability. But the payoff is worth it: products built with a focus on bedrock will outlast and outperform their competitors, and deliver sustained value to users over time. Liam Nugent shows us how.

Discover more from A List Apart

Subscribe now to keep reading and get access to the full archive.

Continue reading