Web APIs
Element.getBoundingClientRect()
Returns a DOMRect bounding the element’s CSS border boxes relative to the viewport; transforms affect the rectangle.
Formal Syntax & Structure
javascript syntaxjavascript
element.getBoundingClientRect()Return Value
DOMRect
Viewport-relative bounding rectangle.
Working Example
Example Snippetjavascript
(async () => {const box=document.createElement("div");box.style.cssText="width:60px;height:20px;padding:5px;border:1px solid";document.body.append(box);const rect=box.getBoundingClientRect();console.log(rect.width,rect.height);box.remove();})()