On most websites, images are the heaviest thing on the page and very often the element that decides Largest Contentful Paint. Getting them right is the quickest performance win available. Work through this list once per template.

1. Use a modern format

  • AVIF gives the smallest files for photos and screenshots; WebP is a close second with wider support in older tools.
  • Keep SVG for logos and icons.
  • Use JPEG or PNG only as a fallback.

An image CDN or your framework's image component can convert automatically and serve the best format each browser accepts.

2. Serve the size it is displayed at

A 2,400-pixel photo shown 800 pixels wide wastes most of its bytes. Offer several widths and let the browser choose:

<img src="hero-1280.avif"
     srcset="hero-640.avif 640w, hero-1024.avif 1024w, hero-1280.avif 1280w, hero-1920.avif 1920w"
     sizes="(min-width: 1024px) 50vw, 100vw"
     width="1280" height="800" alt="Dashboard showing response times">

The sizes attribute tells the browser how wide the image will be, so it can pick before the CSS loads.

3. Always set width and height

Explicit width and height (or a CSS aspect-ratio) let the browser reserve space, so nothing jumps when the image arrives. This is the most common cause of poor CLS.

4. Prioritise the first image, delay the rest

  • The hero or first large image: loading="eager" and fetchpriority="high". Never lazy-load it.
  • Everything below the fold: loading="lazy" and decoding="async".

Lazy-loading the hero image is one of the most common LCP mistakes we see.

5. Compress sensibly

Quality 70 to 80 is usually indistinguishable from 100 for photos. Screenshots with text may need a little more. Compare side by side at the displayed size, not zoomed in.

6. Do not put important images in CSS

Background images in CSS are discovered late, after the stylesheet is parsed. If an image is content or the LCP element, use an <img> in the HTML.

7. Cache them for a long time

Give versioned image URLs a long cache lifetime (Cache-Control: public, max-age=31536000, immutable) and change the URL when the image changes.

8. Write useful alt text

Describe what the image shows and why it is there: "Checkout page with an error message", not "image1.png". Decorative images get an empty alt="". Good alt text helps screen reader users and image search alike (accessibility basics).

Quick audit

Open a page, open the browser's network panel filtered to images, and check: format, transferred size, displayed size vs natural size, and whether the first image is prioritised. Then run the free LCP test to see the effect on a slow phone connection.

What is the best image format for the web?

AVIF usually gives the smallest files, with WebP a close second. Use SVG for logos and icons.

Should I lazy-load all images?

No. Lazy-load images below the fold, but load the first large image eagerly with high priority, because it is often the LCP element.

Why set width and height on images?

So the browser can reserve the right amount of space before the image loads, which prevents layout shift.

Try VitalRix free

Uptime monitoring, APM, logs, real user monitoring and status pages in one place. No credit card needed.