completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

How the metrics are computed

Open Chrome's code that decides LCP, INP and CLS: which paints count, how a tap is timed, how a layout shift is scored, and why Firefox and Safari differ.

By the end, you can
  • 01
    Follow LCP inside ChromeSay which paints become candidates, how Chrome sizes them, and what it skips: flat placeholders, full-screen images, paints after input.
  • 02
    Time a tap the way Chrome doesGroup a tap's events under one interactionId, end its clock at the frame's presentation, round it to 8 ms, and pick INP.
  • 03
    Score layout shifts, and compare enginesWork out a shift's score by hand, build session windows, and explain why Firefox and Safari report different numbers.

One page, two browsers, two LCPs

Ravi builds the Leaf and Kettle tea shop. His real-user data, from Building a RUM pipeline, shows the three Core Web Vitals for every visit: LCP, INP and CLS. He measures them with The web-vitals library. One day, a Firefox visit shows an LCP far better than any Chrome visit. So Ravi loads the Mint tea page twice on his laptop. Once in Chrome, once in Firefox. The server is the same, and the photo arrives late both times. Here is the last LCP entry each browser reported:

The same load, in two browsersPop out in the code editor (opens in a new tab)JavaScript
// The Mint tea page, loaded once in Chrome and once in Firefox: the last LCP entry each reported.const chrome = { url: "mint.jpg", startTime: 1284 };const firefox = { url: "placeholder.png", startTime: 140 }; console.log(`Chrome: LCP at ${chrome.startTime} ms, from ${chrome.url}`);console.log(`Firefox: LCP at ${firefox.startTime} ms, from ${firefox.url}`);console.log(`Firefox's LCP is ${chrome.startTime - firefox.startTime} ms earlier`);
  • Line 1 is a comment. The course recorded both loads, in Chrome 157 and in Firefox 159.
  • Lines 2 and 3 hold what each browser reported: the file, and the startTime in milliseconds (ms) after the visit began.
  • Lines 5 to 7 print Chrome: LCP at 1284 ms, from mint.jpg, Firefox: LCP at 140 ms, from placeholder.png and Firefox's LCP is 1144 ms earlier.

Same page, same network, and the two numbers are more than a second apart. Which browser is right? Both are. Each one followed its own rules. A metric isn't read off the screen with a ruler. Code inside the browser computes it, and that code makes choices. This lesson reads those choices in Chrome's source, at the release the course records with. The last section comes back to Firefox's 140 ms.

Each metric's code runs at a different step of a frame. A frame is one picture on the screen. In Inside the rendering engine, you followed one frame from a script to the screen. Here are the same steps, with the place where each metric is decided:

One frame, left to right: input, style and layout, pre-paint, paint, raster and Viz, then the frame on the screen. Each metric's code runs at one of these steps. INP: when input arrives, Event Timing gives the events an interactionId. CLS: after pre-paint, the layout shift tracker scores what moved. LCP: at paint, Chrome records new images and text. When the frame is on the screen, the presentation time stops the clocks of LCP entries and event durations.CLSscores what movedThe clocks stoppresentation timeInputStyle, layoutPre-paintPaintRaster, VizOn screenINPevents get aninteractionIdLCPnew images and textbecome recordsone frame, left to right
One frame, left to right. Each metric is decided by its own code at its own step. Two of them stop their clocks only when the frame is on the screen.

Event Timing, the code behind INP, starts when input arrives. The layout shift tracker, behind CLS, works right after pre-paint. LCP's code notes what paint drew. Two clocks, LCP's and each event's, stop only when the frame is on the screen.

Real-life analogyJudges at a village show

At a village show, three judges walk around the tents. One measures the biggest pumpkin. One times how fast the tea stall serves each customer. One counts how often a table wobbles. Each judge has a rulebook, and writes in the scorebook at a set moment. Another village's judges may use other rulebooks, and give the same pumpkin another score.

In real life: The judge who measures the biggest pumpkin
In Chrome: LCP's code: the paint detectors and the LCP calculator
In real life: The judge with a stopwatch at the tea stall
In Chrome: Event Timing, for INP
In real life: The judge counting how often the tables wobble
In Chrome: The layout shift tracker, for CLS
In real life: Each judge's rulebook
In Chrome: The specs, and each browser's own code
In real life: The judges at another village's show
In Chrome: Firefox and Safari
The main idea

LCP, INP and CLS are computed by code inside the browser. Each has its own code, its own step in the frame, and its own rules. Change a rule, and the number changes. That's why the same visit can score differently in two browsers.

Which paints can become LCP

LCP is the time the largest image or block of text appeared, as How LCP works showed. The four parts of LCP split that time into parts. This section asks a different question: which element, and which moment? Inside Chrome, two pieces of code watch every paint. The image detector notes each image the first time it paints. The text detector does the same for each block of text. Each note is called a record. Then Chrome's LCP calculator picks among the records.

Size is the area you can see

A record's size is the area you can see, in pixels. On the load, the paragraph's text covered 331 by 42 pixels: 13,902. The photo covered 344 by 229: 78,776. For images, Chrome checks more than size. Here is the code:

Size and detail, shortened from largest_contentful_paint_calculator.cc lines 605 to 663C++
uint64_t size = mapped_visual_rect.size().GetArea();if (size >= viewport_area) {  result.is_viewport_covered = true;  return result;}if (bounding_client_area > natural_area) {  size = static_cast<double>(size) * natural_area / bounding_client_area;}constexpr double kMinimumEntropyForLCP = 0.05;result.entropy = media_timing.ContentSizeForEntropy() * 8.0 / size;result.is_min_entropy_met = result.entropy >= kMinimumEntropyForLCP;

In plain words, line by line:

  1. Line 1: the size starts as the visible area of the image.
  2. Lines 2 to 5: if the image covers the whole viewport, the part of the page you can see, mark it. Chrome treats it as a background, and it can't be LCP.
  3. Lines 6 to 8: if the image is stretched bigger than its own pixels, shrink the size back down.
  4. Line 9: the least detail an image may have, 0.05 bits per pixel.
  5. Line 10: the file's bits for each pixel shown. That's its bytes, from its Content-Length, times 8, divided by the size.
  6. Line 11: the image has enough detail only at 0.05 or more. Otherwise it can't be a candidate.

Chrome calls this number entropy. A photo has lots of detail, so it needs many bytes. A flat colour has almost none, so a tiny file can fill a big box. A comment just above line 9 says the spec uses 0.032 instead. The code decides: in Chrome, the line is 0.05.

Working it out for the placeholder

On the load, two images take turns in the photo's box. While the photo downloads, a flat green PNG fills the box. Here is Chrome's test, done by hand:

Bits per pixel, for the placeholder and the photoPop out in the code editor (opens in a new tab)JavaScript
// The photo's box on the page, and the two files that fill it, in bytes (their Content-Length).const box = 344 * 229;const bitsPerPixel = (bytes) => (bytes * 8) / box;const files = { "placeholder.png": 158, "mint.jpg": 9047 }; for (const [name, bytes] of Object.entries(files)) {  const bits = bitsPerPixel(bytes);  console.log(`${name}: ${bits.toFixed(3)} bits per pixel, ${bits >= 0.05 ? "counts" : "skipped"}`);}
  • Line 2 is the box's area, 344 by 229 pixels.
  • Line 3 turns a file's bytes into bits per pixel.
  • Line 4 holds the two files' sizes, as the server sent them.
  • Lines 6 to 9 print placeholder.png: 0.016 bits per pixel, skipped and mint.jpg: 0.919 bits per pixel, counts.

The placeholder is far under 0.05. So Chrome never makes it a candidate, though it was the largest thing on the screen for over a second. Here is the load, frame by frame:

Three real frames from the load of the Mint tea page in Chrome. At 112 ms, the text paints and the photo's box is empty: Chrome writes an LCP entry for the paragraph, 13,902 pixels. At 127 ms, a flat green placeholder fills the box: no entry, because it has only 0.016 bits per pixel. At 1,287 ms, the photo paints: a new LCP entry, 78,776 pixels.The text paints112 msThe Mint tea card with its heading, paragraph, price and button. The photo's box is still empty.New LCP entrythe paragraph, 13,902 pixelsThe placeholder paints127 msThe same card, with a flat green rectangle filling the photo's box.No entry0.016 bits per pixelThe photo paints1,287 msThe same card, with the photo of a glass of mint tea in the box.New LCP entrythe photo, 78,776 pixels
Three real frames from one load. The placeholder is the largest thing on the screen at 127 ms, and Chrome still writes no entry for it.

Why it matters: in Chrome, a flat placeholder can't hide a slow photo. LCP waits for the real thing.

Entries only grow, and removed content stays

Each frame, the calculator takes its largest new record. It writes a new LCP entry only if that record is larger than the last entry. So LCP entries only ever grow.

What if the largest content leaves the page? The course recorded a second version of the page. A big sale banner covers the top. Then the page's own script removes it, 1.5 s after the load. Chrome kept the banner's entry, at 640 ms. The photo and the text were smaller, so nothing replaced it. Once the banner was gone, the entry's element became null. Chrome's changelog says this rule started in Chrome 88. The spec names the cost: pages with splash screens can get an LCP for content that left.

One case is different. If an element is removed before its frame reaches the screen, its record never becomes a candidate.

Chrome leaves out a few more kinds of paint:

  • Background images on <body> or <html> are never recorded.
  • An image waits until it's loaded before its record counts.
  • Text in a fully transparent colour, with no shadow or outline, isn't recorded.
  • Nothing counts after the first tap, click, key press or scroll. Chrome drops its LCP code for the page right there. Mouse moves and a lone key release don't stop it.
  • Chrome only checks detail for images from the page's own origin, or sent with CORS. A flat image from another site, without CORS, skips the check. Chrome's comment says this stops a page learning another site's file sizes.

Step through the two visits. Each frame is real, and each decision is the one Chrome made:

Playground: what Chrome decided, frame by frame
The load112 ms
The load, at 112 ms: The heading, the paragraph, the price and the button paint. The photo's box is still empty.

What happened: The heading, the paragraph, the price and the button paint. The photo's box is still empty.

Step 1 of 5
Chrome's LCP code: a new entry

New LCP entry: the paragraph, 13,902 pixels, the largest thing painted so far. startTime 112 ms.

Real frames Chrome captured on two recorded visits to the Mint tea page, on a phone-sized screen. Times are in ms after the visit began.
Real-life analogyA tallest-sunflower contest

A village holds a tallest-sunflower contest. A judge measures each sunflower when it opens. The board only changes when a new one beats the record. A sunflower cut down later keeps its record. A cardboard sunflower, painted flat green, doesn't count. When the gates open to visitors, judging stops.

In real life: Measuring a sunflower when it opens
In Chrome: A record, when an image or text first paints
In real life: Writing it on the board only if it beats the record
In Chrome: A new LCP entry only when it's larger than the last
In real life: A cut-down sunflower keeping its record
In Chrome: Removed content stays the LCP
In real life: A flat cardboard sunflower
In Chrome: An image under 0.05 bits per pixel
In real life: The gates opening to visitors
In Chrome: The first tap, click, key press or scroll

Why it matters: a splash screen, or a big banner that goes away, can make Chrome's LCP look better than what Asha actually waited for. Check which element your LCP entry names.

Two times for every paint

When Chrome writes an LCP entry, which time does it use? Every paint has two. First, the main thread finishes its part of the frame. The HTML standard calls this step mark paint timing, near the end of updating the rendering. Chrome notes the time right there. But the frame still has a trip to make: the commit, raster and Viz, from lesson 42.2. Only then is it on the screen.

The Paint Timing spec names both times. paintTime is when the main thread finished. presentationTime is when the frame was presented: shown to the user. Here is where Chrome fills them in:

Paint time and presentation time, shortened from paint_timing.cc lines 398 to 414C++
DOMPaintTimingInfo paint_timing_info{    .paint_time = performance->MonotonicTimeToDOMHighResTimeStamp(        record.rendering_update_end_time),    .presentation_time =        performance->MonotonicTimeToDOMHighResTimeStamp(            frame_timing_details.presentation_feedback.timestamp)};bool coarsen = !performance->CrossOriginIsolatedCapability();if (coarsen) {  paint_timing_info.presentation_time =      (frame_timing_details.presentation_feedback.timestamp -       performance->GetTimeOriginInternal())          .CeilToMultiple(base::Milliseconds(4))          .InMillisecondsF();}

In plain words, line by line:

  1. Line 1: start a record of this frame's paint times.
  2. Lines 2 and 3: the paint time is when the rendering update ended.
  3. Lines 4 to 6: the presentation time is when Viz reported the frame on the screen. Chrome waits for that report.
  4. Line 7: is the page cross-origin isolated? Most pages aren't.
  5. Lines 8 to 14: if not, round the presentation time up to the next multiple of 4 ms. Chrome's changelog says this lowers the risk of a page reading details of other sites' images.

An LCP entry's startTime is the presentation time. Here are the load's two entries:

The load's two LCP entries, both timesPop out in the code editor (opens in a new tab)JavaScript
// The load's two LCP entries in Chrome, in ms after the visit began.const entries = [  { element: "p.about", paintTime: 77.6, presentationTime: 112, startTime: 112 },  { element: "img", paintTime: 1262.8, presentationTime: 1284, startTime: 1284 },]; for (const entry of entries) {  const later = (entry.presentationTime - entry.paintTime).toFixed(1);  console.log(`${entry.element}: on the screen ${later} ms after its paint`);}console.log(entries.every((entry) => entry.startTime === entry.presentationTime));console.log(entries.map((entry) => entry.presentationTime % 4).join(", "));
  • Lines 3 and 4 are the two entries Chrome reported, with both times.
  • Lines 7 to 10 print p.about: on the screen 34.4 ms after its paint and img: on the screen 21.2 ms after its paint.
  • Line 11 prints true: each startTime is the presentation time.
  • Line 12 prints 0, 0: both times are multiples of 4.

The trace holds the exact times: 109.5 ms and 1,282.8 ms. Chrome rounded them up to 112 and 1,284. It also waits until the rounded time before it hands the entry to the page. The page's observer got the photo's entry at 1,284.8 ms.

Real-life analogyPosted, then delivered

You post a birthday card at nine. That's the postmark. It lands on your friend's doormat at eleven, and only then does your friend see it. The post office delivers in rounds, so it writes down the round, not the exact minute.

In real life: The postmark, when you post the card
In Chrome: paintTime: the main thread finished the frame
In real life: The card on your friend's doormat
In Chrome: presentationTime: the frame on the screen
In real life: Writing down the delivery round, not the minute
In Chrome: Rounding up to the next 4 ms

Why it matters: in Chrome, LCP includes the frame's whole trip to the screen. A slow raster or a busy GPU makes LCP later, even after the main thread is done. The same trip is the presentation delay of INP.

How Chrome times a tap

Asha taps Add to basket. The header changes to Basket: 1. How does Chrome turn that tap into a number? First, it has to know which events belong to the tap. One tap fires many: pointerdown, mousedown, pointerup, mouseup, click and more. Event Timing reports each one, as Event Timing and INP showed. An interactionId ties together the ones that belong to one tap.

The course clicked the button twice with the mouse, from a script, so press and release came 0.4 ms apart. Here is the first click, to scale, with two real frames of the header:

The course's first click on Add to basket, recorded in Chrome. Five events, from top: pointerdown with interactionId 5273, mousedown with 0, pointerup with 5273, mouseup with 0, click with 5273. To scale: the press and release at 1,128.5 ms, the handlers on the main thread from 1,135.8 ms to 1,178.4 ms, and the frame on the screen at 1,223.2 ms. The click's exact duration is 94.2 ms, reported as 96 ms. Below, two real frames of the header: Basket: 0 before the click, and Basket: 1 at 1,225 ms.Event and its interactionIdpointerdown: 5273mousedown: 0pointerup: 5273mouseup: 0click: 5273press and release, 1,128.5 mshandlers, 1,135.8 ms to 1,178.4 mson the screen, 1,223.2 ms94.2 ms exactly, reported as 96 ms1,120 ms1,160 ms1,200 msbefore the clickThe header before the click: Leaf and Kettle, Basket: 0.on the screen at 1,225 msThe header after the click: Leaf and Kettle, Basket: 1.
Three of the five events share one id. The click's clock runs from the press to the frame on the screen, then Chrome rounds it to a multiple of 8.

Three of the five events got the id 5273. The mouse events got 0. The second click got 5280: 7 higher. Here is the code that hands out the ids:

Ids for a tap, shortened from responsiveness_metrics.cc lines 394 to 440C++
if (event_type == event_type_names::kPointerdown) {  pending_pointerdown_entries_.Set(pointer_id, new_entry);  return;}if (event_type == event_type_names::kPointerup) {  if (pending_pointerdown_entry) {    interaction_id_for_pointerid = AssignNewPointerInteractionId(pointer_id);    SetInteractionId(pending_pointerdown_entry,                     *interaction_id_for_pointerid);  }  SetInteractionId(new_entry, interaction_id_for_pointerid.value_or(                                  PerformanceTimelineEntryIdInfo::kNone));  return;}  if (interaction_id_for_pointerid) {    SetInteractionId(new_entry, *interaction_id_for_pointerid);

In plain words, line by line:

  1. Lines 1 to 4: a pointerdown gets no id yet. It waits, because the finger might start a scroll.
  2. Lines 5 to 10: at the pointerup, make a new id, and give it to the waiting pointerdown.
  3. Lines 11 to 14: give the pointerup the same id. A pointerup with no pointerdown before it gets 0.
  4. Lines 15 and 16: the click that follows reuses the pointer's id.

If the finger starts a scroll, a pointercancel comes instead, and the pointerdown gets 0. Chrome runs this code just before each event's handlers start, from window_performance.cc. The ids start at a random number from 100 to 10,000, and go up by 7. So don't count taps from the ids. performance.interactionCount counts them for you.

The clock stops at the screen

Each event's duration starts at its timeStamp, the moment of the input. It ends at the presentation time of the next frame. Then Chrome rounds it:

An event's duration, shortened from window_performance.cc lines 901 to 1257C++
  timing->presentation_time =      presentation_details.presentation_feedback.timestamp;// Round to 8ms.int rounded_duration =    std::round((event_end_time - event_creation_time).InMillisecondsF() / 8) *    8;

In plain words, line by line:

  1. Lines 1 and 2: when the next frame is on the screen, write its presentation time on the event.
  2. Line 3 is Chrome's comment: round to 8 ms.
  3. Lines 4 to 6: take the end minus the event's timestamp, divide by 8, round, and multiply by 8.

The trace keeps the exact durations. Round them yourself:

Rounding the two clicks to 8 msPop out in the code editor (opens in a new tab)JavaScript
// The two clicks' exact durations, from Chrome's trace (ms).const exact = [94.185, 44.193];const roundTo8 = (ms) => Math.round(ms / 8) * 8; console.log(exact.map(roundTo8).join(" and "));
  • Line 2 holds the two clicks' exact durations, from Chrome's trace.
  • Line 3 rounds to the nearest multiple of 8, as line 5 of Chrome's code does.
  • Line 5 prints 96 and 48, the durations the page saw.

The first click took 94.2 ms from the press to the screen. Its handlers ran for 40.6 ms of that. About 8.8 ms went before them, and 44.7 ms after them, until the frame was on the screen. Those are the input delay, the processing and the presentation delay from The three phases of an interaction. Chrome keeps an event in the page's buffer only at 104 ms or more. An observer can ask for shorter ones, down to 16 ms.

From interactions to INP

An interaction's latency is its longest event, as How INP works showed. For a whole visit, Chrome keeps the 10 slowest interactions. Then it skips one for every 50 interactions. With fewer than 50, INP is the slowest. The course clicked Add to basket 60 times in a row. Two of the clicks did extra work. Here is Chrome's rule, as a small model:

Chrome's INP rule, as a small modelPop out in the code editor (opens in a new tab)JavaScript
// Chrome's INP rule, as a small model of interaction_to_next_paint_calculator.cc.function inp(slowestTen, interactions) {  const index = Math.min(slowestTen.length - 1, Math.floor(interactions / 50));  return slowestTen[index];}// The 10 slowest of the course's 60 clicks, longest first (ms).const slowestTen = [304, 200, 80, 48, 48, 48, 48, 48, 40, 40]; console.log(`After 49 clicks: ${inp(slowestTen, 49)} ms`);console.log(`After 60 clicks: ${inp(slowestTen, 60)} ms`);
  • Lines 2 to 5 are the rule. Line 3 picks the place in the list as Chrome's code does: one step down for every 50 interactions, and never past the 10 Chrome keeps.
  • Line 7 holds the 10 slowest of the 60 recorded clicks.
  • Line 9 prints After 49 clicks: 304 ms. Under 50, nothing is skipped.
  • Line 10 prints After 60 clicks: 200 ms. 60 / 50 rounds down to 1, so the slowest click is skipped.

That's how INP becomes a high percentile without sorting every interaction. web.dev describes it as ignoring "one highest interaction for every 50 interactions". Slide the playground to change how many clicks count:

Playground: INP over many clicks
The 10 slowest clicksof 60
  1. click 12304 msskipped
  2. click 37200 msINP
  3. click 180 ms
  4. click 248 ms
  5. click 948 ms
  6. click 1048 ms
  7. click 1148 ms
  8. click 1548 ms
  9. click 340 ms
  10. click 440 ms
Try it yourself
INP: 200 ms, from click 37

60 clicks count. 60 / 50 rounds down to 1, so Chrome skips the slowest one and reports click 37: 200 ms.

The course clicked Add to basket 60 times in Chrome. Each duration is the longest event of that click, as Event Timing reported it. Chrome keeps the 10 slowest.
Real-life analogyOrder numbers at a café

At a busy café, you order at the counter. Your order gets one number, and every ticket for it carries that number: the drink, the cake, the bill. The café times each order from the moment you ask until the tray is on your table. At night, the manager looks at the slowest order, but forgives one slow order for every 50 served.

In real life: One order number on every ticket
In Chrome: One interactionId on pointerdown, pointerup and click
In real life: From asking until the tray is on your table
In Chrome: From the input's timestamp to the frame on the screen
In real life: Forgiving one slow order for every 50
In Chrome: Skipping one slowest interaction for every 50

Here are four numbers from this lesson, and when each one's clock stops. Read each row across:

When each clock stops
The numberIts clock stops whenHow Chrome rounds it
An LCP entry's startTimeThe frame with the element is on the screen.Up to the next multiple of 4 ms.
An LCP entry's paintTimeThe main thread finished the rendering update for that frame.No extra rounding.
An event entry's durationThe next frame after the handlers is on the screen.To the nearest multiple of 8 ms.
A layout shift's startTimePre-paint finished, in the frame where things moved.No extra rounding.

Why it matters: INP's clock runs until the pixels are on the screen. Fast handlers aren't enough; the frame after them must be quick too.

Scoring one layout shift

Now the page moves. A second after the load, a promo bar appears under the header: Free delivery on orders over £20. The whole card jumps down. How CLS works gave the formula: impact fraction times distance fraction. Here is where Chrome computes it, and what it measured for this shift.

First, what counts as moving. Chrome tracks where each element's corner sits, its starting point. A move under 3 CSS pixels, both across and down, doesn't count. A move's distance is the larger of the two. For each element that moved, Chrome adds its old place and its new place to one region. Then, after pre-paint:

One shift's score, from layout_shift_tracker.cc lines 548 to 558C++
double viewport_area = double(viewport.width()) * double(viewport.height());double impact_fraction = region_.Area() / viewport_area;double viewport_max_dimension = std::max(viewport.width(), viewport.height());double move_distance_factor =    (frame_max_distance_ < viewport_max_dimension)        ? double(frame_max_distance_) / viewport_max_dimension        : 1.0;double score_delta = impact_fraction * move_distance_factor;

In plain words, line by line:

  1. Line 1: the viewport's area, without scrollbars.
  2. Line 2: the impact fraction is the region's area over the viewport's area.
  3. Line 3: the viewport's longer side.
  4. Lines 4 to 7: the distance fraction is the largest move over that side, and never more than 1.
  5. Line 8: the score is the two multiplied.

For the promo bar, the card moved 60 pixels. Its old and new places together covered 380 by 567 pixels. Here are both frames, and the region, from Chrome's trace:

Two real frames of the Mint tea page in Chrome: at 39 ms, before the shift, and at 1,029 ms, after a promo bar pushed the card down 60 pixels. On the right, the viewport, 412 by 823 pixels, drawn to scale, with the region the card covered before and after: 380 by 567 pixels. Impact 0.6354, distance 0.0729, score 0.0463.before, 39 msThe Mint tea card right under the header.after, 1,029 msA yellow promo bar under the header, and the card pushed down below it.the viewport, to scale380 by 567the card moved 60 pixels downimpact0.6354distance0.0729score0.0463
The card covered 380 by 567 pixels between its old and new places, and moved 60 pixels. Those two facts are the whole score.
The first shift, scored by handPop out in the code editor (opens in a new tab)JavaScript
// The first shift, from Chrome's trace, in CSS pixels: the region the card covered before and after, and how far it moved.const viewport = { width: 412, height: 823 };const region = { width: 380, height: 567 };const moved = 60; const impact = (region.width * region.height) / (viewport.width * viewport.height);const distance = moved / Math.max(viewport.width, viewport.height);console.log(`impact ${impact.toFixed(4)}, distance ${distance.toFixed(4)}`);console.log((impact * distance).toFixed(5));
  • Lines 2 to 4 are the recorded numbers: the viewport, the region and the move.
  • Lines 6 and 7 are the two fractions, as in Chrome's code.
  • Line 8 prints impact 0.6354, distance 0.0729.
  • Line 9 prints 0.04633. Chrome's entry said 0.046326.

Hand and engine agree. The card was big, so the impact was big. It only moved 60 pixels, so the distance was small.

Real-life analogySliding a sofa

You slide a big sofa across the living room, one step. Look at the floor it covered, before and after: a big patch. But it only moved one step. A small stool dragged from wall to wall covers little floor, yet travels far.

In real life: The floor the sofa covered, before and after
In Chrome: The impact region
In real life: The whole floor
In Chrome: The viewport
In real life: How far it slid, against the longest wall
In Chrome: The distance fraction

Why it matters: a big element scores high even for a short move. Keep space free for anything that arrives late above a big block.

From shifts to CLS

The shift page moved four times. Each time, Chrome reported a layout-shift entry:

  • At 1,024 ms, the promo bar pushes the card down. Value 0.0463.
  • At 1,424 ms, a rating line pushes the photo, the text and the button down. Value 0.0175.
  • At 3,051 ms, the course clicks Show details, and the details push the button down. Value 0.0055, with hadRecentInput true.
  • At 4,624 ms, a stock line pushes the button down. Value 0.0014.

Input turns the score off for 500 ms

A mouse press, a key press, a tap, or letting go of the mouse or a finger starts a 500 ms timer. While it runs, every shift gets hadRecentInput true. Chrome still reports the entry, but doesn't add its value. The third shift came less than 5 ms after the click.

Shifts while a finger or mouse button is still down wait too. Chrome holds them until the release, and the release starts the timer first. So dragging something doesn't add to CLS.

Session windows

Chrome groups the rest into session windows. A shift starts a new window if it comes more than 1 s after the last one, or more than 5 s after the window began (the rule, the two sizes). CLS is the largest window. This code runs in Chrome's browser process, which records the page's CLS. Here it is as a small model:

Chrome's session windows, as a small modelPop out in the code editor (opens in a new tab)JavaScript
// Chrome's session windows, as a small model of layout_shift_normalization.cc.function largestWindow(shifts) {  let start = -Infinity, last = -Infinity, sum = 0, largest = 0;  for (const { at, value } of shifts) {    if (at - last > 1000 || at - start > 5000) { start = at; sum = 0; }    last = at;    sum += value;    largest = Math.max(largest, sum);  }  return largest;}// The shifts without recent input, at ms after the visit began.const shifts = [{ at: 1024, value: 0.0463 }, { at: 1424, value: 0.0175 }, { at: 4624, value: 0.0014 }];console.log(largestWindow(shifts).toFixed(4));
  • Lines 2 to 11 are the model. Line 5 starts a new window after a 1 s gap, or after 5 s.
  • Line 8 keeps the largest total so far.
  • Line 13 holds the three shifts without recent input.
  • Line 14 prints 0.0638. The first two shifts, 400 ms apart, share a window. The last came 3.2 s later, on its own.

The Layout Instability spec only sketches CLS as a sum of every shift. The session windows come from Chrome, and from web.dev's definition of CLS. Try both rules, and the input rule, on the four recorded shifts:

Playground: from four shifts to one CLS
Chrome's rule2 groups
ShiftAtValuehadRecentInputWindow
The promo bar1,024 ms0.0463falsewindow 1
The rating line1,424 ms0.0175falsewindow 1
The details, after the click3,051 ms0.0055truenot counted
The stock line4,624 ms0.0014falsewindow 2
Try it yourself
CLS: 0.0638

Shifts within 500 ms after input don't count. A window ends after a 1 s gap, or after 5 s. CLS is the largest window. 2 windows; the largest is window 1.

The four layout-shift entries Chrome reported on the recorded visit, with their times (ms after the visit began) and values.

Why it matters: a burst of small shifts adds up. A shift that a tap asked for, right after the tap, costs nothing. What causes layout shifts and Debugging CLS show how to find the shifts that do count.

Why other browsers report different numbers

Back to Firefox's 140 ms. The Interop project is where browser makers agree on what to fix together. Its Interop 2025 round chose LCP and INP as a focus area. CLS was left out.

The course loaded the same pages in Playwright's builds of Firefox 159 and WebKit 27.2. WebKit is the engine inside Safari. Playwright is a tool that drives real browsers from a script. Same laptop, same server, same clicks. Pick an engine:

Playground: one page, three engines
Chrome3 of 3 entry types

largest-contentful-paint reportedevent reportedlayout-shift reported

LCP entrySizestartTimepaintTimepresentationTime
p13,90211277.6112
img (mint.jpg)78,7761,2841,262.81,284
First click's eventinteractionIdduration
pointerdown527396 ms
mousedown096 ms
pointerup527396 ms
mouseup096 ms
click527396 ms
Try it yourself
Chrome 157.0.8103.52

2 LCP entries on the load; the last one is the img (mint.jpg) at 1,284 ms. The two clicks took 96 ms and 48 ms. It reports all three entry types.

The same three pages and the same clicks, recorded once in each engine on one laptop: Chrome, and Playwright's builds of Firefox and WebKit. Times are in ms after the visit began.

Four differences explain the numbers:

  1. They counted the flat placeholder. Firefox and WebKit both wrote an LCP entry for it. In Firefox, the photo then filled the same box, so it wasn't larger, and it never got an entry. Firefox's LCP stayed at 140 ms. In WebKit, the photo measured 13 pixels more than the placeholder, so it got its own entry, at 1,332 ms.
  2. No presentation time. Both set presentationTime to null. Paint Timing allows a browser without presentation times to use the paint time instead. So their LCP stops when the main thread finishes the frame, before its trip to the screen.
  3. A different end for events. The Event Timing spec ends a duration when the rendering update is done. Chrome ends it later, when the frame is on the screen. For the same two clicks, with 40 ms of work each, Chrome reported 96 and 48 ms. Firefox reported 48 and 40, and WebKit 40 and 40.
  4. No layout shifts. Neither engine lists layout-shift in its supported entry types. There is no CLS to compare.

What they share: all three gave pointerdown, pointerup and click one interactionId, and each next click's id was 7 higher. It's like three referees who agree on the rules of the game, but stop their watches at different whistles. Here is every difference side by side. Read each row across:

The same visits, in three engines
QuestionChrome 157Firefox 159WebKit 27.2
Reports layout-shift entriesYes.No.No.
Last LCP entry on the loadThe photo, at 1,284 ms.The flat placeholder, at 140 ms.The photo, at 1,332 ms.
An LCP entry's presentationTimeWhen the frame was on the screen, rounded up to 4 ms.null.null.
The two clicks, as INP sees them96 ms and 48 ms.48 ms and 40 ms.40 ms and 40 ms.
One id for pointerdown, pointerup and clickYes. The next click's id is 7 higher.Yes. The next click's id is 7 higher.Yes. The next click's id is 7 higher.

Why it matters: never mix engines in one LCP or INP number. Compare each engine with itself over time, as Field data from every browser showed. Firefox's 140 ms isn't a faster page. It's a different rule.

Does Chrome count it?

Each item below is a paint, an event or a shift from this lesson's pages. Sort it by whether Chrome counts it toward LCP, INP or CLS:

Does Chrome count it?
  • A flat placeholder image, 0.016 bits per pixel, for LCP
  • The photo, painted after the paragraph and larger than it, for LCP
  • A banner that became the LCP entry and was then removed
  • A large image that paints after Asha taps the page, for LCP
  • A background image on <body>, for LCP
  • The pointerup of a tap, for INP
  • The mousedown of a click, for INP
  • A pointerdown that turns into a scroll, for INP
  • A shift 300 ms after a click, for CLS
  • A box that moves 2 pixels, for CLS
  • A promo bar that pushes the card down a second after the load, for CLS
Try it yourself
0 of 11 correct

Sort each paint, event or shift by whether Chrome counts it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Common mix-ups

  • "LCP is the largest element on the page when it finishes loading." No. It's the largest paint Chrome counted before the first input. A removed element can stay LCP.
  • "Every image can be LCP." No. Full-viewport images, images under 0.05 bits per pixel, and background images on the body never count in Chrome.
  • "LCP's time is when the main thread painted." No. In Chrome, it's the presentation time, rounded up to a multiple of 4 ms. The paint time comes earlier.
  • "Each event of a tap is its own interaction." No. The pointerdown, pointerup and click share one id. Mouse events get 0.
  • "INP is always the slowest interaction." No. Chrome skips one slowest for every 50 interactions.
  • "CLS adds up every shift on the page." No. It's the largest session window. Shifts within 500 ms of input aren't counted.
  • "Firefox and Safari measure the same numbers as Chrome." No. In the recording, Firefox and WebKit counted the flat placeholder, used the paint time, and reported no layout shifts.

Practice exercises

Answer first, then use the hints.

Exercise 1 · Warm-upA blurred preview

Ravi tries a blurred preview of the photo in the same box. What does this program print?

Starter codePop out in the code editor (opens in a new tab)JavaScript
const box = 344 * 229;
const bitsPerPixel = (bytes) => (bytes * 8) / box;
const preview = 400; // a blurred preview of the photo, in bytes

console.log(bitsPerPixel(preview) >= 0.05 ? "counts" : "skipped");

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upRounding near the middle

    Two events took 19.9 ms and 20.1 ms. What does this program print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    const roundTo8 = (ms) => Math.round(ms / 8) * 8;
    
    console.log(`${roundTo8(19.9)} and ${roundTo8(20.1)}`);

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeThe click Chrome reports

      In the INP playground, count all 60 clicks. Which click number does Chrome report as INP?

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeScore the last shift

        The last shift moved only the button. What does this program print?

        Starter codePop out in the code editor (opens in a new tab)JavaScript
        const viewport = { width: 412, height: 823 };
        const region = { width: 132, height: 80 };
        const moved = 36;
        
        const impact = (region.width * region.height) / (viewport.width * viewport.height);
        const distance = moved / Math.max(viewport.width, viewport.height);
        
        console.log((impact * distance).toFixed(5));

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeCount the interactions

          Open the course's copy of the basket page in Chrome. Click Add to basket three times, and nothing else. Then run performance.interactionCount in DevTools' console. What does it print?

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeA long burst

            A ticker shifts the page every 0.8 s. What does this program print?

            Starter codePop out in the code editor (opens in a new tab)JavaScript
            // Chrome's session windows, as a small model of layout_shift_normalization.cc.
            function largestWindow(shifts) {
              let start = -Infinity, last = -Infinity, sum = 0, largest = 0;
              for (const { at, value } of shifts) {
                if (at - last > 1000 || at - start > 5000) { start = at; sum = 0; }
                last = at;
                sum += value;
                largest = Math.max(largest, sum);
              }
              return largest;
            }
            const shifts = [0, 800, 1600, 2400, 3200, 4000, 4800, 5600].map((at) => ({ at, value: 0.01 }));
            console.log(largestWindow(shifts).toFixed(2));

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask which code decides the number, and when its clock stops.

              The metrics inside Chrome quiz · 8 questionsScore: first tries count
              1. Question 1 of 8What does the bits-per-pixel loop print first?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                // The photo's box on the page, and the two files that fill it, in bytes (their Content-Length).
                const box = 344 * 229;
                const bitsPerPixel = (bytes) => (bytes * 8) / box;
                const files = { "placeholder.png": 158, "mint.jpg": 9047 };
                
                for (const [name, bytes] of Object.entries(files)) {
                  const bits = bitsPerPixel(bytes);
                  console.log(`${name}: ${bits.toFixed(3)} bits per pixel, ${bits >= 0.05 ? "counts" : "skipped"}`);
                }

                Choose an answer to see the explanation.

              2. Question 2 of 8Which time does Chrome put in an LCP entry's startTime?

                Choose an answer to see the explanation.

              3. Question 3 of 8A sale banner became the LCP entry. Then the page removed it. What does Chrome do?

                Choose an answer to see the explanation.

              4. Question 4 of 8Which events of one tap share a non-zero interactionId in Chrome?

                Choose an answer to see the explanation.

              5. Question 5 of 8A page had 120 interactions. Which one does Chrome report as INP?

                Choose an answer to see the explanation.

              6. Question 6 of 8A shift happens 300 ms after Asha clicks Show details. What happens to it?

                Choose an answer to see the explanation.

              7. Question 7 of 8Why did Firefox report an LCP of 140 ms on the load?

                Choose an answer to see the explanation.

              8. Question 8 of 8What puts two shifts in different session windows?

                Choose an answer to see the explanation.

              Key takeaways

              • Chrome records each image and text block when it first paints. A new LCP entry needs a larger record.
              • Full-viewport images, images under 0.05 bits per pixel, transparent text, and paints after input never become LCP. Removed content stays.
              • Every paint has a paint time and a presentation time. Chrome's LCP uses presentation, rounded up to 4 ms.
              • A tap's pointerdown, pointerup and click share one interactionId. Durations run to the next frame on the screen, rounded to 8 ms.
              • INP is the slowest interaction, skipping one for every 50.
              • A shift scores impact times distance. Shifts within 500 ms of input don't count. CLS is the largest session window.
              • Firefox and WebKit counted the flat placeholder, gave no presentation time and reported no layout shifts, so their numbers differ.

              Remember the one-liner.
              Every Core Web Vital is a rule run by the browser's own code at one step of a frame: know the rule before you trust the number.

              Sources

              The facts on this page come from these specs, docs and source files. Chromium's are at the release the course records with:

              Coming next: Deep tracing with Perfetto. You've read the code behind each number. Next, record whole traces and ask them questions.

              CompleteFrontend Clear concepts. Working examples.