Table of contents

  1. 1. Summary
  2. 2. Syntax
  3. 3. Returns
  4. 4. Example
  5. 5. Specification
  6. 6. Notes
  7. 7. References
  8. 8. See also

This content covers features introduced in Firefox 3.

« Gecko DOM Reference


Returns a collection of rectangles that indicate the bounding rectangles for each box in a client.


var rectCollection = object.getClientRects();


The returned value is a collection of ClientRect objects, one for each CSS border box associated with the element. Each ClientRect object 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. For tables with captions, the caption is included even though it's outside the border box of the table.

Originally, Microsoft intended this method to return a TextRectangle object for each line of text. However, the CSSOM working draft specifies that it returns a ClientRect for each border box. For an inline element, the two definitions are the same. But for a block element, Mozilla will return only a single rectangle.

Firefox 3.5 note

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

The amount of scrolling that has been done of the viewport area (or any other scrollable element) is taken into account when computing the rectangles.

The returned rectangles do not include the bounds of any child elements that might happen to overflow.

For HTML AREA elements, SVG elements that do not render anything themselves, display:none elements, and generally any elements that are not directly rendered, an empty list is returned.

Rectangles are returned even for CSS boxes that have empty border-boxes. The left, top, right and bottom coordinates can still be meaningful.

Fractional pixel offsets are possible.


The following examples are screenshots from the attached file.

A paragraph with a span inside. Both the span and the paragraph have a border set. The client rects are in red. Note that the p has only one border box, while the span has multiple border boxes.


A list. Note that the border box doesn't include the number, so neither do the client rects.


A table with a caption. Although the table's border box doesn't include the caption, the client rects do include the caption.


function addClientRectsOverlay(elt) {
  // Absolutely position a div over each client rect so that its border width
  // is the same as the rectangle's width.
// Note: the overlays will be out of place if the user resizes or zooms.
  var rects = elt.getClientRects();
  for (var i = 0; i != rects.length; i++) {
    var rect = rects[i];
    var tableRectDiv = document.createElement('div');
    tableRectDiv.style.position = 'absolute';
    tableRectDiv.style.border = '1px solid red';
    var scrollTop = document.documentElement.scrollTop ||
    var scrollLeft = document.documentElement.scrollLeft ||
    tableRectDiv.style.margin = tableRectDiv.style.padding = '0';
    tableRectDiv.style.top = (rect.top + scrollTop) + 'px';
    tableRectDiv.style.left = (rect.left + scrollLeft) + 'px';
    // we want rect.width to be the border width, so content width is 2px less.
    tableRectDiv.style.width = (rect.width - 2) + 'px';
    tableRectDiv.style.height = (rect.height - 2) + 'px';


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

Tags (3)

Edit tags

Attachments (5)

FileSizeDateAttached by 
Displays the result of getClientRects on various elements.
4.08 kB18:29, 29 Sep 2010yonathanActions
Inline element that is split by a block child.
16.47 kB18:30, 29 Sep 2010yonathanActions
No description
4.34 kB01:22, 9 Sep 2010yonathanActions
No description
6.51 kB02:15, 8 Sep 2010yonathanActions
No description
5.16 kB02:15, 8 Sep 2010yonathanActions

Attach file