Technical article
Optimise images with WebP, AVIF and responsive images
Deliver the right image size for each viewport with modern formats, intrinsic dimensions, lazy loading and LCP priority.
- Performance
- Optimise
- images
- WebP
- AVIF
- responsive

In this article
Optimise dimensions for the image’s actual place on the page, then choose the format. Compare WebP and AVIF at equivalent visible quality. The selected variant, reserved space and loading priority must work together.
From rendered width to files
Illustrative example: a blog image nearly fills a mobile screen and is at most 960 CSS pixels wide on desktop. Export variants such as 480, 800, 1200 and 1600 pixels with the same crop. A high-density screen may use more source pixels. Compare file size and details such as text, faces and edges before settling on quality.
srcset describes available widths; sizes the expected rendered width. The browser chooses. Give each picture source using width descriptors its own sizes attribute. This fragment is for an image below the first viewport; generate the named files yourself.
<picture>
<source type="image/avif" srcset="/images/hero-480.avif 480w, /images/hero-800.avif 800w, /images/hero-1200.avif 1200w, /images/hero-1600.avif 1600w" sizes="(min-width: 64rem) 60rem, 100vw">
<source type="image/webp" srcset="/images/hero-480.webp 480w, /images/hero-800.webp 800w, /images/hero-1200.webp 1200w, /images/hero-1600.webp 1600w" sizes="(min-width: 64rem) 60rem, 100vw">
<img
src="/images/hero-1200.webp"
srcset="/images/hero-480.webp 480w, /images/hero-800.webp 800w, /images/hero-1200.webp 1200w, /images/hero-1600.webp 1600w"
sizes="(min-width: 64rem) 60rem, 100vw"
width="1200" height="675"
loading="lazy" decoding="async"
alt=""
>
</picture>A hero needs a different loading decision
Use lazy loading for suitable images further down, not for the likely LCP image visible immediately. Consider eager loading and fetchpriority="high" for that image. Do not give every image high priority. width and height establish the aspect ratio; preserve it in CSS to avoid movement. A decorative image gets alt=""; describe an informative image according to its purpose.
Inspect the actual download
Inspect currentSrc and the Network panel at narrow and wide viewports. Compare bytes, sharpness and reserved space with a cold cache; repeat with a warm cache. Inspect LCP and CLS alongside file size. The widths above are illustrative design choices, not measured performance gains.
The HTML sample was manually reviewed; sample files and browser downloads were not executed or measured. Check them with your generated images and page layout.
Last updated:


