api-member

Element.getclientrects — CSS reference

Returns rectangles for the element’s CSS box fragments. A wrapped inline can have multiple rectangles; its bounding rectangle is a union and may include empty area between fragments. The example constrains the line width so the two words wrap naturally.

Formal Syntax & Structure

css syntaxcss
Array.from(element.getClientRects())

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>Element.getClientRects</title><style>body{margin:8px;font:16px/20px sans-serif;color:black;background:white}p{margin:0;width:64px;font:16px/20px monospace}</style><body><p><span id="a">First Second</span></p><p>Run once, then reload the page to repeat from the original state.</p><button id="run" type="button">Run example</button><pre id="result" aria-live="polite"></pre><script>const target=document.getElementById('a');const sheet=document.styleSheets[0];async function demo(){const rects=target.getClientRects();return [rects.length,rects[0].top<rects[1].top];}document.getElementById('run').onclick=async()=>{try{document.getElementById('result').textContent=JSON.stringify(await demo());}catch(e){document.getElementById('result').textContent=e.name+': '+e.message;}};</script></body></html>
CSS Reference