Frontend System Design · Lesson 22 of 86 · 4 min
Core Web Vitals: LCP, INP and CLS
You need to explain these three metrics, their causes, and how to fix them—it's a standard performance question.
After this, you'll be able to articulate what each Core Web Vital measures, why it matters for user experience, and the specific technical fixes for common problems. This isn't just theory; it's about demonstrating you can build fast, stable, and responsive UIs.
What LCP actually measures
Largest Contentful Paint (LCP) measures perceived loading speed. It marks the point when the largest image or text block visible in the viewport has rendered. A good LCP reassures the user that the page is useful and loading correctly.
The target is under 2.5 seconds.
The "largest element" can be an <img>, an <image> inside an <svg>, a video's poster image, an element with a background-image, or a block-level element containing text. The browser keeps track of the largest element as the page loads and reports the final one.
The trap: Don't confuse LCP with First Contentful Paint (FCP). FCP is when the first piece of content appears (like a header or a spinner). LCP is when the main content likely appears. An interviewer might ask you to compare them to see if you know the distinction.
A slow LCP is usually caused by one of four things: slow server response times, render-blocking JavaScript and CSS, slow resource load times, or client-side rendering issues.
How to fix a slow LCP
Start by identifying the LCP element using Chrome DevTools (in the Performance tab, look for the LCP marker in the Timings track). Once you know what it is, fix it in this order:
-
Optimize the element itself. If it's an image, this is your highest-impact fix. Compress it, serve it in a modern format like AVIF or WebP, and use
srcsetto provide responsive sizes. No 2MB hero image should ever hit production. -
Prioritize loading the element. Add
<link rel="preload" as="image" href="your-lcp-image.jpg">to the<head>. This tells the browser to fetch the image with high priority, often in parallel with render-blocking CSS, instead of waiting for the<img>tag to be discovered. -
Eliminate render-blocking resources. Audit your scripts and stylesheets in the
<head>. Usedeferfor JavaScript that isn't needed for the initial paint. Split your CSS to inline critical styles needed for above-the-fold content and load the rest asynchronously.
Why INP replaced FID for interactivity
Interaction to Next Paint (INP) measures a page's overall responsiveness to user input. It replaced First Input Delay (FID) because FID only measured the delay of the first interaction. INP is more comprehensive, considering the latency of all interactions throughout the user's visit.
The target is under 200 milliseconds.
INP measures the entire duration from an event (like a click or key press) until the next frame is painted with visual feedback. This includes:
- Input delay: Time spent waiting for the main thread to become available.
- Processing time: Time it takes to run the event handlers.
- Presentation delay: Time it takes the browser to calculate the new frame and paint it.
The interview angle: Explaining why INP is a better metric than FID shows you understand the user experience beyond the initial load. It demonstrates you think about long-lived pages and complex applications, not just simple landing pages. A high INP means your page feels sluggish or "janky."
The primary cause of poor INP is a busy main thread. Long-running JavaScript tasks, large rendering updates, and heavy event handlers all block the browser from responding quickly to user input.
How to stop content from jumping (CLS)
Cumulative Layout Shift (CLS) measures visual stability. It quantifies how much visible content shifts unexpectedly during the page load. A low CLS score means the page layout is stable and predictable.
The target score is 0.1 or less.
The most common cause of CLS is images or ads loading without their dimensions specified. The browser doesn't know how much space to reserve, so when the resource finally loads, it pushes other content down, causing a jarring shift.
The fix is simple: always provide dimensions.
For images and videos, add width and height attributes. The browser uses these to compute an aspect ratio and reserve the correct amount of space before the media loads.
<!-- BAD: Causes layout shift -->
<img src="post-image.jpg" alt="A descriptive alt text.">
<!-- GOOD: Browser reserves space immediately -->
<img src="post-image.jpg" width="800" height="450" alt="A descriptive alt text.">
For responsive images, you still use width and height, but you control the display size with CSS (width: 100%; height: auto;). The browser still knows the intrinsic aspect ratio from the attributes.
A more modern CSS-only approach is the aspect-ratio property. This is great for responsive containers holding images, videos, or embeds.
.image-container {
width: 100%;
aspect-ratio: 16 / 9; /* Reserves a 16:9 space */
background-color: #eee;
}
.image-container img {
width: 100%;
height: 100%;
object-fit: cover;
}
Other common causes are dynamically injected ads, embeds, or banners. For these, you must reserve space in the layout ahead of time, usually by setting a min-height on the container they will load into.
Try it
Open DevTools on a media-heavy site like a news homepage. Use the Performance tab to record a page load. Find the LCP element in the Timings track. Then, enable the "Layout Shift Regions" checkbox in the Rendering panel (find it under More Tools), reload, and see if you can spot and debug what causes content to jump.
Next: We'll look at two other important timing metrics in "FCP and Time to Interactive (TTI) Explained".
Lock it in — apply this lesson under interview conditions.