concept

Forced synchronous layout — CSS reference

Reading geometry immediately after a layout-affecting mutation can force the engine to bring layout up to date synchronously. The read returns current geometry, not the old width. Avoid repeated alternating writes and reads; measure the actual effect in a performance trace.

Formal Syntax & Structure

css syntaxcss
element.style.width = "160px"; element.offsetWidth;

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>forced-synchronous-layout</title><style>body{margin:8px;font:16px/24px sans-serif;color:black;background:white}#a{box-sizing:border-box}#a{width:100px;height:30px}</style><body><div id="a">Sample</div></body></html>
CSS Reference