How it works
The processing model in the HTML Standard has two parts that run side by side.
The loop itself chooses a task queue in an implementation-defined way, takes the first runnable task, runs its steps, and performs a microtask checkpoint. It then reports long tasks and, if there's nothing runnable left, computes an idle deadline for requestIdleCallback. Nothing in this loop draws anything.
In parallel, a window event loop waits until some navigable "might have a rendering opportunity", records the time as the last render opportunity time, and queues a global task on the rendering task source for each navigable with an opportunity. That task is update the rendering. Because it is a task, it competes with other task queues; the spec doesn't fix its priority, and browsers prioritise it in their own ways.
Inside update the rendering, frameTimestamp is the last render opportunity time. The browser builds the list of fully active documents on this event loop, ordered so an iframe's document comes after its parent and siblings follow tree order. Then it filters the list:
- Non-renderable: render-blocked, hidden, suppressed for a view transition, or without a rendering opportunity right now.
- Unnecessary rendering: no visible effect expected and no animation frame callbacks.
- Other reasons: any document the browser prefers to skip, for example to run timer callbacks back to back.
For the documents that remain, the steps run in order: reveal, flush autofocus candidates, resize steps, scroll steps, evaluate media queries and report changes, update animations and send events, fullscreen steps, canvas context-lost checks, animation frame callbacks, then the style and layout loop. That loop recalculates style and layout, determines content-visibility: auto proximity, and delivers ResizeObserver notifications at increasing depth until there are none left. After it: focus fix-up when the focused element stopped being focusable, pending view transition operations, intersection observations, paint timing, and finally "update the rendering or user interface … to reflect the current state", which is where the frame is painted and presented.
Every callback in these steps is invoked from an empty stack, so a microtask checkpoint runs after each one. A promise resolved in a scroll listener settles before the animation frame callbacks start.
Edge cases
- Same event loop, many documents. Same-origin iframes are in their parent's agent and share its event loop, so one frame's update the rendering processes all of them, and a slow iframe callback delays the parent's paint.
- Rendering opportunities are per navigable. An iframe can lack an opportunity while its parent has one; the spec checks again inside the task for that reason.
- Throttled opportunities. The spec's own example: a browser that can't sustain 60 Hz might drop a page to 30 opportunities per second, and a hidden page to 4 per second or fewer.
- Forced layout. Reading geometry mid-task runs style and layout synchronously. It doesn't paint, fire
resize or scroll events, or run animation frame callbacks; those still wait for the rendering task.
- Timer versus frame order. In headless Chrome 156, a
setTimeout(fn, 0) queued alongside a requestAnimationFrame callback ran first in 60 of 60 trials; in headless Firefox 159 the animation frame callback ran first in 60 of 60. Neither order is guaranteed.
Real-world scenario
A click handler shows a spinner, then parses a large file synchronously:
saveButton.addEventListener('click', () => {
status.textContent = 'Saving…';
const data = parseHugeFile(file); // 300 ms of synchronous work
status.textContent = 'Saved';
render(data);
});
The user sees nothing for 300 ms, then "Saved". The spinner text existed in the DOM, but no rendering task could run until the click task ended. The fix is to end the task after the feedback: put the slow part after await scheduler.yield(), or in a setTimeout queued from a requestAnimationFrame callback so it starts after the frame. Better still, move the parsing to a worker so the main thread stays free.
Long tasks also delay the response to the next input, which is what Interaction to Next Paint measures.
Trade-offs
Batching all visual work into one step per frame is what lets the browser compute style and layout once, however many DOM writes a task made. The cost is that the page has no way to "flush" a paint: the only way to show an intermediate state is to end the task and let a rendering opportunity arrive. Code that needs to show progress has to be written as several tasks, and anything that reads layout between writes pays for extra synchronous layouts.