Which means, if you accept user generated content or images from any CMS or other source you really should be obtaining the image dimensions and using them in the HTML.
Which means, if you accept user generated content or images from any CMS or other source you really should be obtaining the image dimensions and using them in the HTML.
To actually prevent jumping (including on lean image load), I believe it would be more effective to simply set width and height.
Assume that developers make essentially random mistakes or changes. Whenever anything happens that has a negative impact on metrics management cares about, there will be pressure to look what went wrong.
Any random change that has a benign impact on measured metrics, eg weird page loading that makes people accidentally click on more lucrative links, there will be no pressure to revert.
No one needs to consciously look for and implement dark patterns for this to work out.
It's very similar to how confirmation bias can make people question news they don't like until they find enough evidence to disregard them; but are just accepting news they do like.
You don't.
You're not required to use it on every image. It's a completely optional parameter that you add to individual images that might benefit from it.
You can use it on navigation icons that don't change size. Maybe in some of your boilerplate in the footer. Or in some sidebar content or a testimonial that you control. But if you have images of unknown size populating the middle of the page, don't use it on those.
The 1.2 kB icon in the footer is not really a problem, but the xxx kB article image some author uploaded with unknown sizes.
Those things will make my page jump around and will need to be lazy-loaded.
The idea to set fixed dimensions feels like it comes from a time where we did designs with tables and "optimized" sites for 1024 x 768 pixel screen size.
That was the time when you could tell that this image should be displayed 200 x 200 px in size and nothing else. And it fit. One way or another.
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_cs...
Make no mistake, this is a silly problem to need to hack a solution for. So I would welcome lazy loaded images with space allocation before it's rendered with a responsive sizing.
I doubt we’ll ever see them built into a browser, because all nice generalized things never get there.
Using js onresize event is a no-go, if JS is still needed the spec is worthless. Lazy loading images with JS worked before just fine, this has to be about not needing special JS for this feature.
No, parent is right: It's impossible to satisfy that recommendation, usually.
Screen relative units represent a percentage of the screen size (technically speaking it's the viewport really). You don't need to know how big the screen is; you're tell the browser to use, for example, 25% of the viewport height when you set something to be 25vh. If you want 4 images vertically that's really useful. That way the browser knows it needs to put a box 25% of the screen height in the DOM where the image will be loaded later so there's no layout thrashing.
Using js onresize event is a no-go, if JS is still needed the spec is worthless.
The parent suggested they would want to change the width and height attributes of the image when the user resizes their browser. That's exactly what the resize event is for. If you want to display a fixed size image you can use fixed width and height attributes. If you want the image to scale with the viewport size you can either use units that represent a relative size or you need to use JS to modify the attributes. Heck, you can even use media queries to mix and match and have fixed size in some devices and relative in others.
Lazy loading images with JS worked before just fine..
Except you needed JS to do it. With the new HTML spec you get the benefits of basic lazy loading without needing the additional weight of some JS code. That's good.
And that's before resizing anything.
And relative units don't fix this either as that information still misses the ratio of my image. If it's 100 vw, how high is it? I don't know this information without fetching the image, doing calculations and dynamically updating the DOM with that information.
I haven't been following the latest developments in CSS for a while, so maybe it's already possible to do this?
I am not going to do this. This is such a pervasive issue, and with an _endless_ difference in screen sizes and millions of pages of content... not going to happen.
This kind of problem is exactly what the browser is best at solving. A problem everyone has on most pages on the internet.
1. The penalty for not displaying image dimensions is nearly insignificant because almost _all_ images that you would put width/height on are from content managers, not designers.
2. Mobile content: On a phone the content moves down after the image is loaded. (everything is just a single column) Which is a preferable action than a big empty space. So, I prefer _not_ including dimensions on user content for phones.
3. Responsive design: All CSS I have been using for years now has "max-width:100%".
Therefore (since a lot of traffic is mobile) most (rough guess) of images loaded from sites I've worked on the image dimensions are recalculated as soon as the image is loaded anyway.
4. Srcset: Multiple possible images downloaded that are _chosen_ by the browser at run time. You already have to provide dimensions. But what if they aren't exact? Go back to #1.
5. Web design: I can't even recall the last time I put an image in a design using the <img> tag that affected layout. (maybe if you go back to the 90s this would have mattered)
Is there an actual problem in identifying what images correspond to your markup and adding an appropriate attribute? (asking, not a web dev)
AFAICT the problem is solved, this is the necessary protocol - not even a bad one, use it and it will work.
Rarely do we specify the width of many, many objects and they display just fine. (consider tables)
If you defer (down)loading of images, and layout depends on unavailable size/aspect-ratio of an image, you get layout updates - same would happen if you lazy-loaded contents of tables.
What is the problem you would like solved and what do you propose for the browsers to do? Ancestor post was about avoiding layout changes as new layout-critical information arrives. Judging by your sibling comment, you seem to prefer layout updates with content popping up.
Why?
1. srcset [0]: the browser chooses the size of the image, not the server.
2. CSS/Responsive images [1] : Almost all (I am close to saying 100%) of images I have loaded on websites have their width/height adjusted by CSS.
Layout updates are often unavoidable in most circumstances surrounding images, there is just no getting around it.
So instead of pining over the past, we should adapt for the future.
I feel like this argument is the same I had with print designers in the late 90s who made every page a full image because they couldn't handle not having full control over the layout.
[0] https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageEl...
[0b] https://cloudfour.com/thinks/responsive-images-101-part-8-cs...
[1] https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimed...