How to optimize images for LCP: a practical guide
Published: · Nooknear
On most pages the largest content element is an image: a product photo, a cover image, a hero. That’s why the fastest way to improve your LCP (Largest Contentful Paint) score usually runs through image optimization. This guide covers the techniques you can apply to speed up the LCP image, along with the mistakes that most often undo them.
Under Google’s Core Web Vitals, a good LCP is 2.5 seconds or less for at least 75% of visits. Within that budget, the image has to be discovered, downloaded and painted.
First, find your LCP element
Don’t start optimizing blind. Record a trace in the Performance panel of Chrome DevTools; the “LCP” marker on the timeline shows which element it is. Lighthouse reports the same thing under “Largest Contentful Paint element”.
Note that the LCP element can change with screen size. On desktop it might be a headline; on mobile, the cover photo. Check both.
1. Make the image discoverable early
The most common cause of LCP delay is the browser finding the image late. While parsing HTML, the browser spots <img> tags early and starts downloading them. But discovery is delayed when the image is added:
- Through CSS
background-image(the browser has to download and parse the CSS first). - As an
<img>injected by JavaScript (the script has to run first). - Through “lazy” patterns like
data-srcattributes.
The rule is simple: the LCP image should be a plain <img> tag in the initial HTML from the server. For client-rendered apps, that may mean server-side rendering or static generation.
If that’s not possible, tell the browser about the image up front with <link rel="preload">:
<link
rel="preload"
as="image"
href="cover-800.webp"
imagesrcset="cover-400.webp 400w, cover-800.webp 800w, cover-1200.webp 1200w"
imagesizes="100vw"
fetchpriority="high">
The imagesrcset and imagesizes values must match the srcset and sizes on the <img> exactly. Otherwise the browser preloads one file, then downloads a different one, and the win disappears.
2. Raise its priority with fetchpriority
Browsers start images at low priority by default and only learn which ones are on screen after layout. fetchpriority="high" skips that wait:
<img
src="cover-800.webp"
srcset="cover-400.webp 400w, cover-800.webp 800w, cover-1200.webp 1200w"
sizes="100vw"
width="1200" height="800"
fetchpriority="high"
alt="A full breakfast spread served on a table">
Use it on one or two images only. Giving everything high priority is the same as giving nothing high priority.
3. Never lazy-load the LCP image
loading="lazy" is great for offscreen images and a real mistake on the LCP image. Lazy loading makes the browser wait until it knows the image is in the viewport, so the download starts late.
A common scenario: a template adds loading="lazy" to every image automatically, and the cover photo gets it too. Check your templates; use loading="eager" (or simply omit the attribute) for above-the-fold images and fetchpriority="high" on the LCP image.
For images below the fold, lazy loading is the right call:
<img src="gallery-1-400.webp" width="400" height="300" loading="lazy" decoding="async" alt="Garden tables">
4. Serve the right size with srcset and sizes
Showing a 2,400-pixel image in a 360-pixel-wide box on a phone means downloading several times more bytes than needed. srcset gives the browser options, and sizes tells it how wide the image will be on the page:
<img
src="product-800.webp"
srcset="product-400.webp 400w, product-800.webp 800w, product-1200.webp 1200w"
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 600px"
width="1200" height="900"
alt="Red ceramic mug">
The browser works out the display width from sizes and the required resolution from the device pixel ratio, then picks the best file. Common mistakes:
- Leaving out
sizes. The default is100vw, so the browser assumes the image fills the viewport and picks a file that’s too large. - Letting
sizesdrift from the layout. If the design changes andsizesdoesn’t, the choice is wrong. - Offering too few candidates. With only 400 and 2,000 pixel options, the browser often has to take the big one.
5. Prevent CLS with width and height
Don’t fix LCP at the expense of CLS (Cumulative Layout Shift). When an image without width and height loads, the content below it jumps down. Modern browsers compute the aspect ratio from those two values and reserve space before the image arrives.
The values don’t have to be the display size; they just need the right ratio. Keep the image fluid with width: 100%; height: auto; in CSS. For images with variable ratios, the aspect-ratio property works too.
6. Switch to modern formats
A smaller file at the same visual quality means a shorter download. WebP is supported in every current browser and usually saves a lot over JPEG. AVIF can produce even smaller files, especially for large photos, but encodes more slowly and is best served with a fallback. For a detailed comparison, see our post on WebP vs AVIF.
Whatever the format, compression settings matter. Dropping quality slightly on cover photos is often invisible to the eye but cuts file size substantially. Try it with your own images using our free image compressor; your files never leave your browser.
7. Don’t forget the server and the connection
However small the image, LCP suffers if the server is slow to respond:
- Same origin or preconnect. If images come from a separate domain, use
<link rel="preconnect" href="https://cdn.example.com">to get DNS, TCP and TLS out of the way early. - CDN and long cache lifetimes. Serve images from servers close to users with a long-lived
Cache-Controlheader. Use a new URL when an image changes, so you never need to purge caches. - Avoid redirects. Every redirect on an image URL adds a round trip.
Checklist
- I identified the LCP element on desktop and mobile.
- The LCP image is a plain
<img>in the initial HTML. - The LCP image has
fetchpriority="high"and noloading="lazy". -
srcsetand an accuratesizesare set. - Every image has
widthandheight(oraspect-ratio). - Offscreen images use
loading="lazy". - Images are WebP (or AVIF where it helps) with sensible compression.
- Images are served from a CDN with long cache lifetimes.
With Nooknear
Every image you upload to Nooknear gets small (400 px), medium (800 px) and large (1200 px) WebP variants generated automatically. The API response includes each variant’s actual width and height, so you can build srcset, width and height straight from it. Images are served through the Cloudflare CDN with long cache headers and no bandwidth fees. See our quickstart to get started.