<div></div>
<pre id="output"></pre>Range: getClientRects() method / notebook
Range: getClientRects() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
div {
height: 80px;
width: 200px;
background-color: blue;
}const range = document.createRange();
range.selectNode(document.querySelector("div"));
rectList = range.getClientRects();
const output = document.querySelector("#output");
for (const rect of rectList) {
output.textContent = `${output.textContent}\n${rect.width}:${rect.height}`;
}