Skip to content

Lesson 6 of 14 · 23m

Image Strategy: Formats, Sizing, and the LCP Image

The LCP image must be discoverable, prioritized, correctly sized, and never lazy-loaded — the three rules that fix most image-driven LCP.

On most content and commerce pages the LCP element is an image — and on most of those pages the image is wrong in at least one of three ways: it's discovered late, it's far bigger than its display size, or it's served in a format from 1992. Fix all three on the hero and you'll often take a full second off LCP without touching application code.

Rule one: the LCP image must be discoverable and prioritized

The preload scanner finds <img> tags in raw HTML almost immediately. It cannot find images set by CSS background-image, injected by JavaScript, or rendered client-side after hydration — those all surface as huge resource load delay.

<img
  src="/img/trail-runner-3-1200.avif"
  srcset="/img/trail-runner-3-640.avif 640w,
          /img/trail-runner-3-960.avif 960w,
          /img/trail-runner-3-1200.avif 1200w,
          /img/trail-runner-3-1800.avif 1800w"
  sizes="(min-width: 1024px) 50vw, 100vw"
  width="1200" height="900"
  fetchpriority="high"
  alt="Trail Runner 3 in slate blue, side view">

fetchpriority="high" tells the browser this image outranks the other images it has found — images default to low priority until layout proves they're in view. If the hero truly can't live in the HTML, preload it: <link rel="preload" as="image" imagesrcset="..." imagesizes="..." fetchpriority="high">.

Rule two: never lazy-load the LCP image

loading="lazy" defers the request until layout confirms the image is near the viewport — after CSS has loaded and layout has run. On the hero that's pure added delay, and it is the single most common LCP regression I see — usually a component library defaulting every <Image> to lazy. Lazy everything below the fold; the one image that is the LCP loads eagerly, prioritized.

Rule three: serve the right bytes

  • Size: srcset with w descriptors plus an honest sizes lets the browser pick the smallest file covering the slot at the device's pixel ratio. A wrong sizes — or none, which defaults to 100vw — quietly makes phones pull desktop-sized images.
  • Format: AVIF runs ~30–50% smaller than JPEG at the same perceived quality; WebP ~25–30%. Every current browser supports both. Keep <picture> + <source type="image/avif"> only if you still need a JPEG fallback for ancient clients.
  • Quality: AVIF at q50, WebP at q75 look fine for photos. Nobody sees the difference between q85 and q95 on a phone; everyone feels the extra 300 KB.

Generate variants once in a build step rather than trusting editors to export correctly:

// scripts/build-images.mjs — `node scripts/build-images.mjs`
import sharp from "sharp";
const widths = [640, 960, 1200, 1800];
for (const w of widths) {
  await sharp("src/img/trail-runner-3.jpg")
    .resize({ width: w, withoutEnlargement: true })
    .avif({ quality: 50 })
    .toFile(`public/img/trail-runner-3-${w}.avif`);
}

Videos are not exempt either

A looping hero video is an LCP element wearing a costume — its poster is what LCP records, so give the <video> a poster attribute pointing at a proper AVIF/WebP frame and treat it exactly like the hero image: discoverable in HTML, fetchpriority="high" on the poster via <link rel="preload" as="image">. The video bytes themselves should load lazily (preload="none" or a click-to-play facade); a 6 MB MP4 autoplaying in the hero is a load-duration bomb.

Dimensions prevent layout shift

Always set width and height (or CSS aspect-ratio). The browser uses the ratio to reserve space before a single byte arrives, so content below doesn't jump when the image lands. Missing dimensions remain the most common CLS cause on the web — the CLS lesson covers the rest of that story.

Field notes

  • Check the LCP element in field data per device: a carousel's first slide, a text heading, and a video poster each need different fixes.
  • decoding="async" is fine below the fold; on the LCP image it can occasionally push paint a frame later. Measure before sprinkling.
  • An image CDN (on-the-fly resize + format negotiation via the Accept header) beats a build step once you accept user uploads — make sure it sends Vary: Accept.
  • A fade-in on the hero delays the LCP timestamp until the image is actually painted. Designers should know the trade they're making.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.