Skip to main content
CodingMarble

Web development

Core Web Vitals Explained: LCP, INP and CLS

Core Web Vitals are three measurements of real user experience: how fast the main content appears (LCP), how quickly the page responds to input (INP) and how much the layout jumps (CLS). Each has a published threshold, a short list of usual causes and a specific fix.

By CodingMarble · Published · 5 min read

A silver iMac on a desk in a bright room
Photo: Lee Campbell on Unsplash

What Core Web Vitals are and why they exist

Core Web Vitals are a small set of metrics defined by Google and documented on web.dev that describe loading, interactivity and visual stability from the visitor's point of view. They replaced a long tradition of measuring things that were easy for a server to count, such as the time to first byte or the total page weight, with measurements of what a person actually perceives. A page can be light and still feel slow if the main image appears late, and a page can load quickly and still be frustrating if buttons move as you tap them.

The current set is Largest Contentful Paint, Interaction to Next Paint and Cumulative Layout Shift. Google has changed the set before, for example when INP replaced First Input Delay, so check web.dev for the present definitions before you build a reporting dashboard around them. They are one signal among many in search, and good scores will not rescue weak content, but poor scores are also a real usability problem regardless of rankings.

LCP: how fast the main content appears

Largest Contentful Paint records when the largest image or block of text in the viewport finishes rendering. The published good threshold is 2.5 seconds or less, measured at the 75th percentile of page loads, and anything above 4 seconds is classed as poor. The 75th percentile matters: it means three out of four visits must meet the threshold, so a fast median is not enough.

LCP failures usually come from one of four places. The server responds slowly, so nothing can start. The LCP resource is discovered late, for example a hero image set as a CSS background or inserted by JavaScript, so the browser cannot request it early. The resource itself is too large. Or render-blocking CSS and scripts hold back painting. In the DevTools Performance panel, the LCP marker shows which element it was; Lighthouse names it under the LCP diagnostic.

Fixes follow the cause. Serve the page from a cache or a CDN so the first byte arrives sooner. Make the hero a real img element in the HTML with a sensible width and height, a responsive srcset and, for that one image only, fetchpriority set to high. Never lazy-load the LCP image. Compress and resize it. Inline the small amount of critical CSS and defer the rest.

HTML· A discoverable, prioritised LCP image with reserved dimensions.
<img
  src="/img/hero-800.jpg"
  srcset="/img/hero-480.jpg 480w, /img/hero-800.jpg 800w, /img/hero-1600.jpg 1600w"
  sizes="100vw"
  width="1600" height="900"
  fetchpriority="high"
  alt="Storefront with the new summer range">

INP: how quickly the page responds

Interaction to Next Paint observes the clicks, taps and key presses during a visit and reports roughly the slowest interaction, measured from the input until the browser can paint the next frame. The good threshold is 200 milliseconds or less, and above 500 milliseconds is poor. Unlike LCP, INP covers the whole visit, so a page that loads fine can still fail because of what happens later, such as opening a filter panel on a large product list.

The usual cause is a busy main thread. Long tasks from big JavaScript bundles, heavy event handlers, expensive re-renders in a framework, or third-party tags leave the browser unable to respond. The fix is to do less work in the handler and to split what remains. Update the visible state first, then defer non-urgent work. Break loops over large data into chunks and yield between them.

JavaScript· Yield to the browser so the click can paint before heavy work runs.
button.addEventListener("click", async () => {
  panel.hidden = false; // show feedback immediately

  // let the browser paint before the expensive part
  await new Promise((resolve) => setTimeout(resolve, 0));

  const html = buildLargeListHtml(items);
  list.innerHTML = html;
});

In a React app, look for state that sits too high and causes a whole tree to re-render, long lists that are not virtualised, and effects that run on every keystroke. The Performance panel shows long tasks as red-cornered blocks; click one to see which function consumed the time.

CLS: how much the layout moves

Cumulative Layout Shift adds up unexpected movements of visible elements during the page's life, scored from how much of the viewport moved and how far. The good threshold is 0.1 or less, and above 0.25 is poor. It is unitless, so do not read it as seconds or pixels.

The causes are predictable. Images, videos and iframes without declared dimensions push content down when they load. Ads, cookie banners and embeds inserted above existing content do the same. Web fonts that swap in with different metrics reflow text. Content injected by script after a delay, such as a promotional bar, shifts everything below it.

Fixes: always set width and height attributes, or the CSS aspect-ratio property, so the browser reserves space before the file arrives. Give ad and embed slots a minimum height. Insert banners in space that was already reserved, or overlay them rather than pushing content. Use font-display with fallback metrics adjusted, or a framework font loader that does this for you.

CSS· Reserve space for media and for a late-loading banner.
img, video {
  max-width: 100%;
  height: auto;
}

.video-frame {
  aspect-ratio: 16 / 9;
  width: 100%;
}

.promo-slot {
  min-height: 56px; /* the banner fills this space, so nothing below moves */
}

Shifts that happen within a short time after a tap or click are not counted against you, because the user expected something to change. Unexpected shifts during scrolling or loading are what the metric catches.

Lab data versus field data

Lab data comes from a controlled test, such as Lighthouse or WebPageTest, run on a chosen device and network. It is repeatable and gives you a trace to debug, which makes it the right tool for finding and fixing problems. It cannot tell you what your audience experiences, because it does not click anything, and a plain Lighthouse run does not measure INP at all; it reports Total Blocking Time as a stand-in that tends to move in the same direction.

Field data comes from real users, collected by Chrome and published in the Chrome UX Report, and it is what Google's assessment uses. You can see it in PageSpeed Insights, in the Core Web Vitals report in Search Console, and from your own code with the web-vitals JavaScript library. Field data lags by weeks, covers only users of supported Chrome browsers, and requires enough traffic to appear. Low-traffic sites may see nothing at all, in which case rely on lab data and your own measurements.

A workable routine

  1. Open the Core Web Vitals report in Search Console and note which groups of URLs are marked poor or needing improvement, and for which metric.
  2. Reproduce the problem on one representative URL in Lighthouse or the Performance panel, with CPU and network throttling on, and identify the exact element or task responsible.
  3. Make one fix, deploy, and rerun the same lab test to confirm the specific number moved.
  4. Use the validate fix option in Search Console, then expect to wait several weeks for field data to reflect the change.
  5. Add the web-vitals library to report real values from your own visitors, so you can see regressions after future releases.

Resist chasing a perfect Lighthouse score. A page that meets the three thresholds for most real visits has done its job, and the time is usually better spent on content and usability.

Need this built properly for your business?

CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.