Web performance and Core Web Vitals
Measure how fast your pages feel to real users with LCP, INP and CLS, and fix the few things that matter most.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
Vodafone had a landing page that people reached from paid ads: display, search, social, and iOS and Android. The team wanted to know if performance work alone would change sales. 1
So they ran an A/B test. Half the traffic went to the old page and half to a faster one. The only difference was the Web Vitals work on the faster page. Each version got about 34,000 visits a day. 1
The faster page did three things. It moved a widget's rendering from the browser to the server, so less JavaScript blocked rendering. It rendered the important HTML on the server. And it resized the hero image, made SVGs and PNGs smaller, and did not load images outside the screen. 1
They measured real users with the browser's PerformanceObserver API. Largest Contentful Paint dropped from 8.3 seconds to 5.7 seconds, 31% better. Total sales rose by 8%. The lead-to-visit rate rose by 15%, and the cart-to-visit rate by 11%. 1
Note one detail. An older metric, DOMContentLoaded, got 15% worse on the faster page. 1 If the team had watched only that number, they could have rolled back a change that made money. You must measure what users feel.
The idea in simple words
A page can be slow in three different ways. It can be slow to show its main content. It can be slow to react when you tap. Or it can jump around while you read. Google's Core Web Vitals give one number for each. 3
| Metric | What it measures | Good | Poor |
|---|---|---|---|
| LCP | When the largest image, text block or video in view is shown 5 | ≤ 2.5 s | > 4.0 s 5 |
| INP | How fast the page shows a response to clicks, taps and key presses 7 | ≤ 200 ms | > 500 ms 7 |
| CLS | How much content moves without the user asking 10 | ≤ 0.1 | > 0.25 10 |
INP replaced First Input Delay (FID) as a Core Web Vital in March 2024. 8 If an old dashboard still shows FID, it is out of date.
You judge each metric at the 75th percentile of page loads, for phones and desktops separately. A page passes only if all three are good at that point. 3 Google chose the 75th percentile so that most visits get the target experience, while a few outliers do not move the number much. 4
The key idea. Speed is three separate problems: loading, responding and staying still. Measure all three on real users, at the 75th percentile, and fix the biggest one first.
How it works
Step through one page load, from the first request to the first tap. Use Next and Back, or the ← and → keys.
- This is a made-up page with example timings. The user taps a link. The browser looks up the name, opens a connection, does TLS and sends the request.
- After 0.6 seconds the first byte of the HTML arrives. That wait is the time to first byte. It includes redirects, DNS, the connection, TLS and the server's work.
- The browser parses the HTML and finds a stylesheet and a normal script in the head. CSS is render-blocking, so nothing is painted until the CSS is loaded and processed.
- The browser combines the DOM and the CSS rules into a render tree, does layout and paints. The first text appears at 1.4 seconds.
- The hero image is the largest thing in view. It is painted at 2.2 seconds, so LCP is 2.2 seconds. That is inside the 2.5-second good limit.
- The user taps Add to cart. A 300 ms JavaScript task is already running, so the tap waits. The next frame appears 340 ms after the tap. That is above the 200 ms good limit for INP.
- An ad image without a width and height loads late and pushes the button down. The user did not ask for this move, so it counts toward CLS. A score of 0.15 is above the 0.1 good limit. All the timings and scores here are examples.
The critical rendering path
The browser turns your files into pixels in a fixed order. It parses HTML into the DOM and CSS into the CSSOM. It combines them into a render tree, works out the layout, then paints. 13
CSS is render-blocking: the browser waits for all the CSS before it paints, because later rules can change earlier ones. Some requests, such as scripts, can also stop the HTML parser until the file is handled. 13 So stylesheets, and scripts without defer or async, in the head can delay the first paint. MDN's advice: defer what is not critical, mark scripts async, or remove them. 13
LCP: four parts
LCP has four parts. First comes the time to first byte. Then there is a delay before the LCP resource starts loading, its load time, and a delay before it is painted. The web.dev guide suggests about 40% for TTFB, about 40% for the load, and under 10% for each delay. 6
TTFB covers redirects, DNS, the connection, TLS and the server's work. As a rough guide, most sites should aim for 0.8 seconds or less. TTFB is not a Core Web Vital 12, but it is the first part of LCP. 6 The latency lesson shows why far-away servers cost so much.
INP: the main thread
Almost all of your JavaScript runs on one main thread, which does one task at a time. A task longer than 50 ms is a long task. While it runs, the browser cannot handle a tap. 9
An interaction has three phases: the input delay, the time your event handlers run, and the time until the next frame is shown. 7 A long task that is already running makes the first phase long. A slow handler makes the second phase long.
CLS: things that move
A layout shift counts when it is unexpected. Shifts within 500 ms of a tap, click or key press do not count. 10 The common causes are images and videos without a size, web fonts that render larger or smaller than the fallback font, and ads or widgets that resize themselves. 10
The biggest fixes
Send less JavaScript. Large bundles cost time to parse, compile and run, and that work blocks the main thread. Split the bundle with dynamic import() and send only what the first view needs. 19
Break up long tasks. Yield to the main thread between pieces of work, for example with scheduler.yield() or setTimeout. 9
Make the LCP image early and small. Start loading it at the same time as the first resource on the page. If it is hidden in CSS or JavaScript, preload it with fetchpriority="high". Never lazy-load it. 6 Use loading="lazy" only for images below the first view. 20
Reserve space. Set width and height on every image and video, or use CSS aspect-ratio. Reserve space for ads with min-height. For fonts, use font-display: optional, or use size-adjust so the fallback font takes up about the same space. Animate with transform, not top or left. 11
Connect early. rel="preconnect" lets the browser open a connection to an important third-party origin early. The web.dev guide reports 100–500 ms saved, but too many preconnects compete for bandwidth. 21
Cut TTFB and cache. Serve static files and cacheable HTML from a CDN close to users. The CDN and caching lesson shows how. Fewer round trips also help, see the HTTP versions lesson.
Lab data and field data
Lab data comes from loading a page in a controlled setup. Field data comes from all the real users who visit it. 14 Lighthouse is a lab tool. 3 You can run it in Chrome DevTools, from the command line, as a Node module or in PageSpeed Insights. 15
The two often disagree. Lab tests use one device, one network and usually a cold cache. They cannot predict when a user will tap, so they cannot measure INP directly. Total Blocking Time is a lab metric meant to help diagnose INP problems. 14 But it is not a substitute for INP, so a good TBT does not promise a good INP. 24
For field data, the Chrome UX Report (CrUX) shows how real Chrome users experience popular sites. 16 But it leaves out Chrome on iOS, Android WebViews and other Chromium browsers such as Microsoft Edge. 17 So also collect your own real user monitoring. The web-vitals library, about 3 KB compressed, reports LCP, INP and CLS from each visit to your own endpoint. 18
redBus did this. Its real user data showed slow interactions on the search page. Loading 10 results per batch instead of 30 cut INP there from about 870–900 to 350–370. 2 The case study gives no unit, but INP is measured in milliseconds. 7 Overall, redBus reported 7% more sales. 2
Trade-offs
| Option | Fast first content? | Good INP? | Use it when |
|---|---|---|---|
| Static rendering | Yes HTML is ready, so TTFB stays low. 22 | Yes , if you ship little JavaScript. 22 | Pages that are the same for everyone: blogs, docs, landing pages. |
| Server-side rendering | Yes , but building HTML per request can raise TTFB. 22 | Depends. Hydration can hurt INP, because the page looks ready before it can respond. 22 | Personal or fast-changing pages that still need content in the first HTML. |
| Client-side rendering | No The browser must download and run JavaScript first. | Gets worse as the bundle grows. 22 | Apps behind a login, used for a long time per visit. |
| Lazy-load every image | No A lazy LCP image starts loading later. 6 | No effect. | Never. Lazy-load only below the first view. |
| Lazy-load below the first view | Yes Fewer bytes compete with the LCP image. | No effect. | Long pages, lists and feeds. Set image sizes too. 20 |
At work: how a senior uses this
- Report LCP, INP and CLS at the 75th percentile, split by phone and desktop. Treat them like SLOs, as in the observability lesson.
- Ask "which metric is bad, for which pages, on which devices?" before anyone writes a fix.
- Add a performance budget to CI. The web.dev example is "less than 170 KB of JavaScript on mobile" for a product page. Tools like Lighthouse CI run checks on every commit to catch regressions. 23 25 See the CI/CD lesson.
- Review every new third-party script like a dependency. Ask who owns it and what it costs on the main thread.
- Check that the LCP image is in the HTML, not lazy, and sized for the screen.
- When you show speed work to the business, use a real A/B test, like Vodafone did. 1
With AI
What to ask the agent
"Find the LCP element on our product page. Check that it is in the initial HTML, not lazy-loaded, has width and height, and uses fetchpriority=high. List what to change."
"Find event handlers in this component that do more than 50 ms of work. Propose how to split them and yield to the main thread, without changing behaviour."
"Add the web-vitals library to send LCP, INP and CLS to our /analytics endpoint, with the page type and device type on each event."
What to check yourself
- The agent did not add
loading="lazy"to every image, including the hero. - Any new
preloadorpreconnectis for a resource the page truly needs early. Too many slow other requests down. - Code splitting did not move needed code behind an
import()that runs on the first tap. - You measured the change on real users, not only in one Lighthouse run.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 25 sources and related lessons
- web.dev, Vodafone case study: LCP improvement and sales (2021) (opens in a new tab)
An A/B test of two landing pages that differed only in Web Vitals work, with the changes and the business results. - Amit Kumar and Saurabh Rajpal, “How redBus improved their website's Interaction to Next Paint (INP)”, web.dev (case study, 2023) (opens in a new tab)
How redBus found slow interactions with field data and fixed them, and the sales result. - web.dev, “Web Vitals” (opens in a new tab)
The three Core Web Vitals, their good thresholds, the 75th percentile rule, and which tools give lab or field data. - web.dev, “How the Core Web Vitals metrics thresholds were defined” (opens in a new tab)
Why Google chose the 75th percentile, and how the 2.5 s and 0.1 thresholds were picked. - web.dev, “Largest Contentful Paint (LCP)” (opens in a new tab)
What counts as the largest element, and the good and poor values. - web.dev, “Optimize Largest Contentful Paint” (opens in a new tab)
The four parts of LCP and how to shorten each one. - web.dev, “Interaction to Next Paint (INP)” (opens in a new tab)
Which interactions count, the three phases of an interaction, and the thresholds. - web.dev blog, announcement that INP is a Core Web Vital (March 2024) (opens in a new tab)
The announcement that INP replaced First Input Delay as a Core Web Vital. - web.dev, “Optimize long tasks” (opens in a new tab)
What a long task is, why it blocks input, and how to yield to the main thread. - web.dev, “Cumulative Layout Shift (CLS)” (opens in a new tab)
How layout shifts are scored, which shifts count, and the common causes. - web.dev, “Optimize Cumulative Layout Shift” (opens in a new tab)
Image sizes, space for ads, font settings and safe animations. - web.dev, “Time to First Byte (TTFB)” (opens in a new tab)
What TTFB includes and the rough 0.8 s guide. - MDN Web Docs, “Critical rendering path” (opens in a new tab)
DOM, CSSOM, render tree, layout and paint, and why CSS blocks rendering. - web.dev, “Why lab and field data can be different (and what to do about it)” (opens in a new tab)
Why a Lighthouse run and your real users often disagree. - Chrome for Developers, “Introduction to Lighthouse” (opens in a new tab)
What Lighthouse is and the ways to run it. - Chrome for Developers, “Overview of CrUX” (opens in a new tab)
What the Chrome UX Report is. - Chrome for Developers, “CrUX methodology” (opens in a new tab)
Which Chrome users and platforms are included, and which are not. - GoogleChrome, “web-vitals” library (GitHub) (opens in a new tab)
A small library to measure LCP, INP and CLS on real users and send them to your analytics. - web.dev, “Reduce JavaScript payloads with code splitting” (opens in a new tab)
Why less JavaScript at startup helps INP, and how dynamic import() splits a bundle. - web.dev, “Browser-level image lazy loading for the web” (opens in a new tab)
How loading="lazy" works, and why images in the first view should not use it. - web.dev, “Establish network connections early to improve perceived page speed” (opens in a new tab)
What preconnect does, the savings, and why too many preconnects hurt. - web.dev, “Rendering on the Web” (opens in a new tab)
Server-side, static and client-side rendering and hydration, and how each affects TTFB and INP. - web.dev, “Performance budgets 101” (opens in a new tab)
Types of budgets and tools that enforce them in the build. - web.dev, “Total Blocking Time (TBT)” (opens in a new tab)
How TBT adds up main-thread blocking after First Contentful Paint, and why it is only a lab proxy for INP. - GoogleChrome, “Lighthouse CI” (GitHub) (opens in a new tab)
Run Lighthouse on every commit and fail on regressions.
Related: CDNs and HTTP caching · HTTP/1.1, HTTP/2 and HTTP/3 · CI/CD and trunk-based development · Observability, SLOs and error budgets · Latency numbers and back-of-envelope maths