Yastatic

Images that fit the layout they are in

Width and height attributes, srcset with honest sizes, and when not to lazy-load.

An image without dimensions is a promise that the page will jump. The browser does not know how much room to reserve until the file starts arriving. Always set width and height; CSS can still make the image fluid, and the aspect ratio is preserved.

Responsive images are mostly about telling the truth in the sizes attribute. If the image is displayed at half the viewport on wide screens, say so. The default assumption is the full viewport, and the browser will download a file twice as large as needed.

<img src="/img/desk-800.webp"
     srcset="/img/desk-400.webp 400w, /img/desk-800.webp 800w, /img/desk-1600.webp 1600w"
     sizes="(min-width: 60em) 50vw, 100vw"
     width="800" height="533" alt="A desk with a laptop">

Lazy loading is good for everything below the fold and harmful above it. The hero image is usually the largest contentful paint; marking it loading="lazy" delays the very thing the visitor is waiting for.

Formats matter less than people think once the dimensions are right. A correctly sized JPEG beats an oversized AVIF every time.