IT lexicon › Web › Forced reflow

Forced reflow

Web På svenska → Updated: 2026-11-16

When JavaScript reads layout properties like `offsetHeight` or `clientWidth`, forcing the browser to immediately flush pending layout changes.

Browsers normally batch CSS changes and run reflow asynchronously. But when JavaScript reads layout information, the value must be current — the browser cannot guess. This forces a synchronous reflow, often called "synchronous layout thrashing" when repeated in loops.

Example: `for (let el of elements) { console.log(el.offsetHeight); el.style.height = "100px"; }` triggers one reflow per element. The fix is to batch reads then writes: `const heights = elements.map(e => e.offsetHeight); elements.forEach((e, i) => { e.style.height = "100px"; })`.

← Back to the lexicon