By the ImageOpti team ·
Image Optimization for Core Web Vitals: LCP, CLS and What to Fix First
How images affect Largest Contentful Paint and Cumulative Layout Shift, and the practical fixes: sizing, width and height attributes, lazy loading and srcset.
Images affect two of Google's Core Web Vitals directly. They are often the element that determines Largest Contentful Paint (LCP), and images without reserved space cause Cumulative Layout Shift (CLS). You improve both by serving appropriately sized, compressed files, setting width and height on every image, and being careful about what you lazy load.
This guide sticks to what Google documents and what browsers do. It does not promise ranking jumps, because Core Web Vitals are one signal among many and nobody outside Google can say how much any single change is worth.
What the metrics measure
Core Web Vitals are a set of measurements about real-world page experience. The three current ones are:
| Metric | What it measures | Google's "good" threshold |
|---|---|---|
| Largest Contentful Paint (LCP) | How long until the largest visible content element has rendered | 2.5 seconds or less |
| Cumulative Layout Shift (CLS) | How much visible content jumps around while loading | 0.1 or less |
| Interaction to Next Paint (INP) | How quickly the page responds to clicks and taps | 200 milliseconds or less |
INP is mostly about JavaScript, so images matter far more for the first two. Google assesses these at the 75th percentile of real visits, which means a page is judged on what most of its visitors experience, not on a single fast test on your own computer.
Google also states that page experience is one of many signals, and that great content still matters most. Treat these fixes as ways to make a page pleasant to load, which is worth doing for visitors regardless.
How images affect LCP
On many pages the LCP element is an image: a hero banner, a product photo or the first picture in an article. The time to render it is roughly the sum of four parts.
- The delay before the browser even discovers the image.
- The delay before it starts downloading.
- The time to download the file.
- The time to render it.
You mostly control step 3 and, to some extent, steps 1 and 2.
Make the file smaller
Download time depends on file size and connection speed. On a slow mobile connection, every extra 100 KB is noticeable. A 3 MB hero image is a common cause of a poor LCP, and it is also easy to fix.
Do these in order:
- Resize to the display size. If the image shows at 1200 pixels wide at most, a 4000 pixel original wastes data. The resizer reduces dimensions in your browser.
- Choose the right format. Photos are normally smaller as JPEG, WebP or AVIF than as PNG. The converter switches formats.
- Compress. The optimizer re-encodes JPEG, PNG and WebP with a quality slider and a before and after comparison.
A typical full-width hero photo can often be brought into the region of 150 to 400 KB without visible loss at that size, though it varies with the photo.
Do not lazy load the LCP image
This is one of the most common mistakes. The loading="lazy" attribute tells the browser to delay an image until it is near the viewport. That is helpful for images far down the page, but for an image that is visible immediately it adds delay. Google's web.dev guidance is explicit: do not lazy load images that appear in the initial viewport, especially the LCP image.
Use lazy loading for images that start below the fold:
<img src="gallery-4.jpg" width="800" height="600" loading="lazy" alt="...">
And leave it off for the main image at the top.
Hint that the main image is important
Browsers can only start fetching an image once they find it in the HTML or after CSS or JavaScript reveals it. An image set as a CSS background, or inserted by a script, is discovered late. Where possible, use a normal <img> element in the HTML so the browser sees it straight away.
The fetchpriority="high" attribute is documented on web.dev as a way to tell the browser that a specific image, such as the LCP image, should be fetched with higher priority:
<img src="hero.jpg" width="1600" height="900" fetchpriority="high" alt="...">
Use it sparingly, on one or two images. If everything is high priority, nothing is.
How images cause layout shift (CLS)
Layout shift happens when something moves after the user has started looking at the page. With images, the cause is simple. If the browser does not know how tall an image will be, it reserves no space. When the file arrives, the picture pushes the text below it downwards. That jump is what CLS counts.
Set width and height on every image
The fix recommended by Google and documented in web.dev is to include width and height attributes on image elements:
<img src="photo.jpg" width="1200" height="800" alt="A description">
Modern browsers use those two numbers to work out the aspect ratio (here 3:2) before the image has loaded, and they reserve the right amount of space. The attributes are in pixels and describe the image's intrinsic size, not necessarily the displayed size. You can still make the image responsive with CSS:
img { max-width: 100%; height: auto; }
With height: auto, the browser keeps the aspect ratio from your attributes while scaling the image to fit the container. Without width and height, the browser has nothing to calculate the space from.
Other causes of shifts
Images are not the only culprit, but similar principles apply.
- Ads, embeds and iframes that load late without reserved space.
- Web fonts that swap and change text size.
- Banners or cookie notices injected at the top after the page has begun to render.
For each, reserve the space in advance with a fixed size or an aspect-ratio rule.
Responsive images with srcset and sizes
A phone and a large desktop monitor do not need the same file. The srcset attribute lets you provide several versions and lets the browser choose.
<img
src="photo-800.jpg"
srcset="photo-480.jpg 480w, photo-800.jpg 800w, photo-1600.jpg 1600w"
sizes="(max-width: 700px) 100vw, 700px"
width="1600" height="1067"
alt="A description">
Here is how to read it:
srcsetlists the available files and states each file's actual width in pixels with thewdescriptor.sizestells the browser how wide the image will be displayed at different screen widths, so it can pick the best candidate before layout is finished.- The browser also considers the screen's pixel density. A phone with a high-density screen may choose a larger file than its CSS width suggests.
A worked example
Say your content column is 700 CSS pixels wide on desktop and the full screen width on phones. On a 400 pixel wide phone with a 3x density screen, the image area is 400 CSS pixels, which is 1200 device pixels. The browser would likely choose the 1600 pixel file, not the 480 one. On a 1x desktop monitor showing the image at 700 pixels, the 800 file is enough.
You can create these versions with the resizer by exporting the same image at several widths. Make each from your original, not from a smaller copy, so each stays sharp. Then run each through the optimizer.
Responsive images are worth the effort when images are large or visitors are mostly on mobile. For a small site with modest images, one well-sized file may be adequate.
Modern formats
WebP and AVIF generally produce smaller files than JPEG for similar visual quality, and all current major browsers support WebP. You can offer alternatives with the <picture> element so browsers pick the first format they support:
<picture>
<source srcset="photo.avif" type="image/avif">
<source srcset="photo.webp" type="image/webp">
<img src="photo.jpg" width="1200" height="800" alt="A description">
</picture>
For a comparison of the formats, see AVIF vs WebP vs JPEG, or the introduction to WebP.
A prioritised checklist
If you only have an hour, work through this list in order of impact.
- Find the largest image above the fold. Make sure it is resized to its display size and compressed.
- Remove
loading="lazy"from that image. Considerfetchpriority="high". - Add
widthandheightto every<img>on the site. - Add
loading="lazy"to images below the fold. - Convert large PNG photos to JPEG or WebP.
- Add
srcsetandsizesfor your biggest, most visible images.
How to measure
Do not guess. Google provides tools that report these metrics.
- PageSpeed Insights shows lab data and, where available, real-user field data for the page.
- Chrome DevTools (Performance and Lighthouse panels) can identify the LCP element and highlight layout shifts.
- Search Console has a Core Web Vitals report grouped by URL type, based on real-user data.
Lab tests run on a simulated device and connection, so numbers will differ from field data. Field data is what Google uses for assessment, and it can take a few weeks to reflect changes because it is collected over a rolling period.
For a broader walk-through of speeding up a site through images, see the checklist for compressing images for a faster website.
FAQ
Do image changes alone fix Core Web Vitals?
Sometimes, but not always. If your LCP is an image, optimizing it can help a lot. If the cause is slow server response, render-blocking scripts or something else, images will not solve it.
Should every image have width and height?
Yes, as a general rule. Set them to the image's intrinsic pixel dimensions and let CSS control the displayed size.
Should I lazy load all images?
No. Lazy load images below the fold, but not the main image visible when the page first loads.
Is WebP or AVIF required for good scores?
No. A well-sized, well-compressed JPEG can pass. Modern formats give extra savings on top.
Will better Core Web Vitals raise my search ranking?
Google lists page experience as one signal among many. Improvements are good for visitors, but no particular ranking change is guaranteed.
Related guides
To build this into your process, see the image workflow for developers, and for the wider picture the image optimization guide for websites.