Start from the viewport rect. Same getBoundingClientRect() call.
Add scrollY / scrollX. Converts viewport space → document space (MDN).
Stable while scrolling. Document coords stay put as the viewport moves.
Use when needed. Anchors, canvas overlays, or saving layout positions.
Compatibility
Browser Support
Element.getBoundingClientRect() is Baseline Widely available (MDN: across browsers since July 2015). Safe to use in modern evergreen browsers.
✓ Baseline · Widely available
getBoundingClientRect()
Returns a DOMRect with size and position relative to the viewport.
99%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
getBoundingClientRect()Excellent
Bottom line: Use for tooltips, hit-testing, and layout measurements — remember values are viewport-relative and include the border box.
Frequently Asked Questions
It returns a DOMRect with the element’s size and its position relative to the viewport. Properties include top, left, right, bottom, x, y, width, and height in pixels (MDN).
No. MDN marks Element.getBoundingClientRect() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes. MDN: the returned rectangle is the border box, including padding and border-width (not only content). With box-sizing: border-box, width/height match the CSS width/height.
Yes. top, left, right, and bottom are relative to the viewport, so they change when the page scrolls. Add window.scrollX and window.scrollY for document coordinates (MDN).
clientWidth is a single number for inner width. getBoundingClientRect() returns a full DOMRect with both size and viewport position.
Use getClientRects() when an element spans multiple lines (like inline text) and you need one rectangle per fragment. getBoundingClientRect() returns the union of those boxes (MDN).