3 ms·
If you just want this to avoid layout shift, you're still better off using explicit width and height attributes (on the img tag), because it is per-image in the
by Tomte 5y ago
If you just want this to avoid layout shift, you're still better off using explicit width and height attributes (on the img tag), because it is per-image in the HTML itself, not in a common CSS declaration. Is that right?
- fleddr 5y agoRegardless of whether you use this CSS rule or not, it's a best practice to ALWAYS set the width and height attributes of any image. So even if you use this CSS rule, you should also set those width and height attributes. This allows the browsers to draw the correctly sized box whilst the image is still loading and whilst CSS hasn't kicked in yet.