Introduced in Gecko 1.9

(Firefox 3)
« Gecko DOM Reference


Returns a text rectangle object that encloses a group of text rectangles.


var rectObject = object.getBoundingClientRect();


The returned value is a TextRectangle object which is the union of the rectangles returned by getClientRects() for the element, i.e., the CSS border-boxes associated with the element.

The returned value is a TextRectangle object, which contains read-only left, top, right and bottom properties describing the border-box, in pixels, with the top-left relative to the top-left of the viewport.

Gecko 1.9.1 note
(Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Firefox 3.5 adds width and height properties to the TextRectangle object.

Empty border-boxes are completely ignored. If all the element's border-boxes are empty, then a rectangle is returned with a width and height of zero and where the top and left are the top-left of the border-box for the first CSS box (in content order) for the element.

The amount of scrolling that has been done of the viewport area (or any other scrollable element) is taken into account when computing the bounding rectangle. This means that the top and left property change their values as soon as the scrolling position changes (so their values are relative to the viewport and not absolute). If this is not the desired behaviour just add the current scrolling position to the top and left property (via window.scrollX and window.scrollY) to get constant values independent from the current scrolling position.

Gecko 12.0 note
(Firefox 12.0 / Thunderbird 12.0)

Starting in Gecko 12.0 (Firefox 12.0 / Thunderbird 12.0) , the effect of CSS transforms is considered when computing the element's bounding rectangle.

For cross-browser compatibility, use window.pageXOffset and window.pageYOffset instead of window.scrollX and window.scrollY, except use (((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollLeft == 'number' ? t : document.body).ScrollLeft and (((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop when window.pageXOffset and window.pageYOffset (and window.pageXOffset and window.pageYOffset) are undefined.


var rect = obj.getBoundingClientRect();

Browser compatibility

  • Desktop
  • Mobile

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 3.0 (1.9) 4.0 (Yes) 4.0
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.0 1.0 1.0 (1.9) 6.0 (Yes) 4.0



getBoundingClientRect() was first introduced in the MS IE DHTML object model.

Tags (5)

Edit tags

Attachments (0)


Attach file