# Browser Event Loop

The browser event loop coordinates queued tasks, microtasks, user input, scripts, and rendering while JavaScript jobs run to completion.

- Type: framework
- Domain: Engineering & architecture
- Level: Intermediate
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/browser-event-loop/>)

## What it means

A browser event loop is the HTML processing model that schedules work for a window or worker agent. It selects tasks from task queues, performs microtask checkpoints, and gives window loops rendering opportunities. JavaScript within a job runs to completion, but event loops are not simply a single FIFO callback queue and do not necessarily map one-to-one to operating-system threads.

## Why it matters

Long tasks delay input and rendering even when network operations are asynchronous. Task and microtask ordering explains stale UI, timer behavior, promise callbacks, race-like bugs, and why resolved data may not appear immediately.

## When to use it

Use the model when debugging asynchronous order, responsiveness, timers, promises, event handlers, or rendering delays. Move CPU-heavy independent work to a worker and break cooperative main-thread work into bounded tasks where appropriate.

## How it works

1. Platform activity queues tasks from sources such as input, timers, parsing, and networking.
2. The event loop selects a runnable task and its JavaScript executes to completion.
3. A microtask checkpoint drains queued promise reactions and other microtasks.
4. A window loop may update rendering between tasks when a rendering opportunity occurs.
5. Long work is measured and split, deferred, or moved off the main agent to protect responsiveness.

## A practical example

A search interface parses a large response in one callback, freezing input despite using fetch. Profiling reveals a long main-thread task, so the team moves parsing to a worker and renders results in small batches.

## Where it breaks

Specifications define ordering constraints but browsers retain scheduling freedom. The model alone does not expose every engine thread, rendering stage, priority, or background throttling rule, and worker communication still has cost.

## Common mistakes

- Calling every queued callback a microtask.
- Assuming a zero-delay timer runs immediately.
- Creating an unbounded microtask chain that prevents rendering opportunities.
- Believing asynchronous I/O makes its follow-up computation non-blocking.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/browser-event-loop/#visualization-browser-event-loop>)

## Sources

1. [HTML Standard: Event Loops](<https://html.spec.whatwg.org/multipage/webappapis.html#event-loops>) — WHATWG · Living web standard
2. [JavaScript Execution Model](<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Execution_model>) — MDN Web Docs · Official technical documentation

## Related topics

- [Web Worker](<https://wiki.soroush.uk/topic/web-worker/>)
- [Critical Rendering Path](<https://wiki.soroush.uk/topic/critical-rendering-path/>)
- [Client-Side Rendering \(CSR\)](<https://wiki.soroush.uk/topic/client-side-rendering/>)
