Ankit KanojiyaIntermediate

Evergreen guide by Ankit Kanojiya · Intermediate · Frontend

Core Web Vitals: A Practical Guide to Frontend Performance

What LCP, INP, and CLS actually measure, and concrete techniques to improve each one. Includes the thresholds that matter and how to measure in the field.

Core Web Vitals are a small set of metrics meant to capture real user experience: how fast the main content loads, how quickly the page responds to input, and how stable the layout stays. Unlike synthetic scores, they are designed to reflect what a person actually perceives. Each has a target threshold and a distinct set of causes.

The three metrics

  • Largest Contentful Paint (LCP) measures loading. It marks when the largest visible element, often a hero image or heading block, finishes rendering. Good: 2.5 seconds or less.
  • Interaction to Next Paint (INP) measures responsiveness. It captures the latency of user interactions across the whole visit and reports a representative worst case. Good: 200 milliseconds or less.
  • Cumulative Layout Shift (CLS) measures visual stability. It sums unexpected layout movement during the page's lifetime. Good: 0.1 or less.

INP replaced First Input Delay because it accounts for the full interaction, not just the delay before processing begins.

Improving LCP

LCP is usually dominated by how quickly the largest element can be discovered, downloaded, and painted.

  • Serve the LCP image in a modern format and an appropriately sized resolution.
  • Preload the hero image so the browser fetches it early:
<link rel="preload" as="image" href="/hero.avif" fetchpriority="high" />
  • Avoid lazy-loading the LCP image. Lazy loading is for below-the-fold content.
  • Reduce render-blocking CSS and slow server response times, since both delay the first paint.
  • Prefer server-rendered or statically generated markup for above-the-fold content so it does not wait on client-side JavaScript.

Improving INP

INP suffers when the main thread is busy and cannot respond to a click, tap, or keypress. Long tasks are the usual culprit.

  • Break up long JavaScript tasks so the browser can respond between chunks.
  • Defer non-urgent work. Yielding to the main thread lets a pending interaction run first:
async function handleClick() {
  updateUrgentUI();
  // Yield so the browser can paint the response
  await new Promise((resolve) => setTimeout(resolve, 0));
  doExpensiveWork();
}
  • Ship less JavaScript. Code splitting and removing unused dependencies shrink parse and execution time.
  • In React, keep event handlers light and move heavy computation out of the interaction path, or mark non-urgent updates as transitions.

Improving CLS

Layout shifts happen when content loads and pushes existing content around. The fixes are mostly about reserving space in advance.

  • Always set width and height (or an aspect ratio) on images and video so the browser reserves the box before the asset loads:
img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}
  • Reserve space for ads, embeds, and dynamically injected banners.
  • Avoid inserting content above existing content after load, unless it is a response to user interaction.
  • Use font-display strategies that minimize reflow when web fonts swap in, and preload critical fonts.

Lab versus field data

There are two ways to measure these metrics, and they answer different questions.

  • Lab data comes from tools like Lighthouse, run in a controlled environment. It is reproducible and good for debugging, but it is a single simulated session.
  • Field data, also called real user monitoring, comes from actual visitors on real devices and networks. It is what reflects user experience over time.

A page can score well in the lab and poorly in the field because real users have slower devices, weaker networks, and unpredictable interaction patterns. Treat lab data as a diagnostic and field data as the source of truth.

Measuring in code

The web-vitals library reports these metrics from real sessions:

import { onLCP, onINP, onCLS } from 'web-vitals';

onLCP(console.log);
onINP(console.log);
onCLS(console.log);

Send the values to an analytics endpoint and watch the distribution, not just the average. The 75th percentile is the common reporting point, because a good experience for most users matters more than a good average skewed by fast devices.

A working method

  • Start from field data to find which metric is actually failing.
  • Reproduce the problem in the lab with throttling that matches your real users.
  • Apply the targeted fix for that specific metric rather than optimizing everything at once.
  • Re-measure in the field after the change ships, since lab improvements do not always translate.

Performance work pays off most when it is driven by real measurements and focused on the single metric that is hurting users.