Your event handler only needs 250 ms. But the person who clicked waits 530 ms for the screen to change. Where did the rest go?
INP (Interaction to Next Paint) is the Core Web Vitals metric for responsiveness: the time from a user's click, tap or key press until the screen shows the result in the next frame. You already know its limits from the Core Web Vitals lesson. Here we take it apart. Picture ordering coffee at a busy café: you wait for the cashier to finish with the person before you, the barista makes your coffee, then it's brought to your table. The time you feel is all three added up, not just how long the barista worked.
The three parts of an interaction
All of a page's JavaScript, and also style, layout and paint, is done on one and the same lane: the main thread. It can only do one thing at a time. One interaction goes through three parts:
- Input delay: from the click until the event handler starts running. Long when the main thread is busy with another task.
- Processing time: how long the event handler runs. This is your code.
- Presentation delay: from the handler finishing until the next frame has been drawn: the browser works out the style, layout and paint for the change.
| Part | Cause in the example | Time |
|---|---|---|
| Input delay | the analytics script that is running | 180 ms |
| Processing time | the "Add to cart" handler | 250 ms |
| Presentation delay | 1,500 rows drawn again | 100 ms |
| This interaction's INP | 530 ms |
The total is 530 ms, and that is poor. The limits: good is at most 200 ms, needs-improvement up to 500 ms, poor above 500 ms. A value of exactly 200 is still good. A page's INP is taken from the slowest interaction during the visit (with a very large number of interactions, a few of the most extreme are ignored), then Google grades it at the 75th percentile of real visits.
INP replaced FID (First Input Delay) in March 2024. FID only measured the input delay, and only for the first interaction. In the example above the FID is 180 ms and looks good, while the user waits 530 ms.
Long tasks: why the main thread gets stuck
A long task is a task that runs on the main thread for more than 50 ms. While a long task runs, the browser can't run the click handler and can't draw. The 180 ms analytics script and the 250 ms handler above are both long tasks.
function classifyInp(milliseconds) {
if (milliseconds <= 200) return "good";
if (milliseconds <= 500) return "needs-improvement";
return "poor";
}
function identifyBlockingTasks(tasks) {
return tasks.filter((task) => task.duration > 50); // long task: more than 50 ms
}
console.log(classifyInp(530)); // "poor"
const tasks = [
{ name: "parseHTML", duration: 30 },
{ name: "evalScript", duration: 120 },
{ name: "styleRecalc", duration: 20 },
{ name: "fetchData", duration: 80 },
];
console.log(identifyBlockingTasks(tasks));
// [{ name: "evalScript", duration: 120 }, { name: "fetchData", duration: 80 }]
<=at both limits:classifyInp(200)is"good",classifyInp(500)is"needs-improvement", andclassifyInp(501)is"poor".task.duration > 50, not>=: a 50 ms task isn't a long task yet, a 51 ms task is.filterreturns a new array of the task objects that pass, in their original order. If none pass, the result is[].
Yield: give the main thread a chance
The main way to shrink INP is to yield: split long work into short pieces, and between the pieces, hand the main thread back to the browser so it gets a chance to draw and take clicks.
function yieldToMain() {
if (globalThis.scheduler?.yield) return scheduler.yield();
return new Promise((resolve) => setTimeout(resolve, 0)); // fallback
}
button.addEventListener("click", async () => {
updateCartBadge(); // what the user sees is done first
for (const chunk of chunks) {
await yieldToMain(); // the browser may draw and take clicks first
processChunk(chunk); // each piece under 50 ms
}
});
updateCartBadge()runs before the first yield, so the next frame already shows the new cart count. This interaction's INP stops counting at that frame.scheduler.yield()returns a Promise. After theawait, the rest carries on in a new task, and goes ahead of other tasks waiting in line. Not every browser has it yet, so there's asetTimeout(resolve, 0)fallback, which puts the rest at the back of the line.- The yield is inside the loop. If it happens only once, the rest of the work is still one long task that can become the input delay of the next click.
In the example above, if the analytics script is also split into 50 ms pieces and the handler yields after 12 ms, the INP becomes 50 + 12 + 100 = 162 ms: good.
| The big part | How to shrink it |
|---|---|
| Input delay | split other long tasks with yields, defer third-party scripts |
| Processing time | do what the user sees first then yield, debounce heavy handlers, move heavy computing to a Web Worker |
| Presentation delay | change as little DOM as possible: batch, virtual scrolling, avoid layout thrashing |
⚠️ An INP that stays bad, and limits that miss
- Only measuring the handler. A 30 ms handler feels fast, but if the input delay is 300 ms, the INP is still bad.
- Yielding only once. The 238 ms left that runs in one go is still a long task. Yield at every piece.
<at the limits. In the exercise,classifyInp(200)must be"good"andclassifyInp(500)must be"needs-improvement".>= 50for a long task. A 50 ms task isn't a long task yet. What counts is more than 50.
TL;DR: INP is the time from an interaction until the next frame is drawn: input delay + processing time + presentation delay. Good is at most 200 ms, needs-improvement up to 500 ms, poor above 500 ms, and a page's INP comes from its slowest interaction. INP replaced FID in March 2024, which only measured the input delay of the first interaction. A long task is a task of more than 50 ms on the main thread. Shrink INP by yielding: do what the user sees first, then await scheduler.yield() (with a setTimeout fallback) between short pieces.
⚡ The three parts of an interaction
Guess first: your handler only takes 250 ms. Why does the person who clicked wait 530 ms?
INP counts from the click until the next frame is drawn: an input delay of 180 ms (the analytics script that is running), a processing time of 250 ms (your handler), and a presentation delay of 100 ms (drawing again).
Meaning: Good is at most 200 ms, needs-improvement up to 500 ms, poor above 500 ms. A page's INP comes from its slowest interaction.
⚡ Long tasks jam the main thread
Write:
function identifyBlockingTasks(tasks) {
return tasks.filter((task) => task.duration > 50);
}
Meaning: A long task is a task of more than 50 ms on the main thread. While it runs, the browser can't run the click handler and can't draw. A 50 ms task isn't a long task yet.
⚡ Yield at every piece
Write:
updateCartBadge();
for (const chunk of chunks) {
await yieldToMain();
processChunk(chunk);
}
Meaning: Do what the user sees first, then hand the main thread back to the browser between short pieces. Yielding only once isn't enough: the rest of the work is still one long task.