← Glossary

What Are Client Rects?

Client rects are the rectangles a browser reports for an element's rendered boxes through getClientRects() and getBoundingClientRect(), measured in CSS pixels relative to the viewport. They describe layout at a moment in time and change with scrolling, zoom, fonts and window size.

Updated:

Client rects are the rectangles that describe where an element's boxes sit on screen. Layout creates CSS boxes for elements that generate boxes, and the DOM exposes their positions and sizes through two methods. Element.getClientRects() returns a collection of rectangles, one per border box, each giving top, left, right, bottom, width and height in pixels relative to the top-left corner of the viewport. Element.getBoundingClientRect() returns a single rectangle that encloses all of them. The numbers are the output of the browser's layout engine for the current document, window, fonts and zoom, which makes them useful for positioning tooltips, detecting visibility and measuring text, and also makes them vary between machines. That variability is why client rects appear in discussions of browser identification, a context in which they are often described with more certainty than the measurements deserve.

Rectangles, Coordinate Spaces and Layout

A client rect is reported in the viewport coordinate space. MDN describes each rectangle from getClientRects as the border box in pixels with the top-left relative to the top-left of the viewport, and notes that the amount of scrolling of the viewport or any other scrollable element is taken into account. For ordinary content moving with the document, scrolling down by 100 CSS pixels reduces its top value by that amount. Fixed and sticky positioning can behave differently because those elements do not necessarily move with the document. Converting to document coordinates means adding the current scroll offsets.

The rectangle covers the border box: content, padding and border, but not margin. For getBoundingClientRect, MDN states that width and height include padding and border-width rather than only the content dimensions, which, for an untransformed box, reflects content width plus padding and border in the standard box model, or the specified width with border-box sizing. Transforms can change the returned bounding dimensions. Overflowing children are not included; the rectangle is the element's own box, even if a child extends beyond it. Elements that are not rendered, such as those with display set to none, produce an empty collection from getClientRects, and getBoundingClientRect returns a zero rectangle when there are no boxes. If boxes exist but all are empty, its zero-size result uses the first box's position.

Values are not restricted to whole numbers. MDN notes that fractional pixel offsets are possible, which follows from sub-pixel layout: text metrics, percentage widths and transforms all produce coordinates such as 183.4375. Two browsers, or one browser on two machines with different fonts or display scaling, can lay out the same markup to slightly different fractions.

getClientRects Compared With getBoundingClientRect

AspectgetClientRects()getBoundingClientRect()
Return valueA collection of DOMRect objects, one per border boxA single DOMRect
Multiline inline elementOne rectangle per line fragmentThe union enclosing all fragments
Block elementUsually one rectangleThe same rectangle
Table with captionCaption included even though it is outside the table border boxUnion including the caption
Element with display:none and no rendered boxesEmpty collectionZero-width, zero-height rectangle
Typical useHighlighting or wrapping each line of inline textPositioning, hit testing, visibility checks

The difference matters most for inline content. A span that wraps across three lines has three border boxes, one per line, and getClientRects returns all three so that an overlay can be drawn around each fragment. getBoundingClientRect collapses them into one rectangle that encloses the minimum and maximum extents of all fragments and includes the empty space in between. MDN's definition of the bounding rectangle as the union of the rectangles from getClientRects describes exactly this relationship. For list items, the marker is outside the border box and therefore outside both measurements; for SVG elements inside an outer svg, the rectangles are additionally transformed by the viewBox.

Everyday Uses of DOM Geometry

Layout rectangles drive a large share of interactive behaviour. Tooltips and dropdowns read the anchor element's bounding rectangle to decide where to appear and whether to flip above or below. Drag-and-drop code compares pointer coordinates to rectangles to find the drop target. Lazy loading and analytics check whether an element's rectangle intersects the viewport, though the Intersection Observer API now handles that without polling. Text editors and annotation tools use per-line rectangles from getClientRects to draw selection highlights that follow wrapped text. Test automation reads rectangles to click the centre of an element or to assert that two elements do not overlap. Virtualised lists measure rendered rows to decide how many to keep in the document.

Measurement Variability and the Fingerprinting Context

Because the values depend on layout, they depend on everything layout depends on: the fonts available and their metrics, the default font size, the device pixel ratio and display scaling, the browser's zoom level, the window size, the operating system's text rendering, and the rendering engine's own rounding. Rendering a fixed snippet of text in a known font fallback and reading its rectangles produces numbers that differ in small fractions between environments, and identification scripts collect such measurements as one input among many. In that context the technique is sometimes called ClientRects fingerprinting, and it is a separate subject from the API itself.

The measurements have known limits as a signal. They are not unique: different environments can produce the same measured values, particularly for simple content or common configurations. They are not stable: zoom, window size, font changes or browser updates may change the values, depending on the measured content and layout. They are influenced by the page's own stylesheet, so they describe the page as rendered rather than the device as such. A rectangle measurement is one coarse layout observation, not an identifier, and its usefulness for recognition depends on the test, stability and overlap with other visitors rather than a claim of guaranteed uniqueness.

Limits and Practical Cautions

Reading rectangles can require the browser to complete pending layout, so calling the methods repeatedly inside a loop that also modifies styles causes layout thrashing and slow pages; batching reads before writes avoids it. The values are a snapshot and are stale as soon as anything moves, which is why visibility and position logic should re-read on scroll and resize or use observers. CSS transforms change where an element appears, and the rectangles reflect the transformed position, which can surprise code that expected layout coordinates. Finally, visual invisibility does not necessarily remove boxes: visibility:hidden and opacity:0 elements can still have geometry. An element with display:none has no boxes to measure; creating a measurement layout is then necessary and can itself change the result. Client rects answer one question well, where an element's boxes are right now in this window, and everything built on them inherits the conditions of that answer.

Frequently asked questions

Why can one element have multiple rectangles?

Because an inline element that wraps across lines has one border box per line fragment, and getClientRects returns each of them. Block elements usually have a single box. The bounding rectangle is the union of all fragments, including the space between them.

Do scrolling and zoom affect results?

They can. Ordinary document content moves relative to the viewport during scrolling, while fixed and sticky elements have different behaviour. Zoom, resizing and fonts may change layout, but not every change in device scaling necessarily changes a particular CSS-pixel measurement.

Is a rectangle measurement a unique identifier?

No measurement is guaranteed unique to a device or person. Different environments can yield identical rectangles, and one environment can yield different results after layout or software changes. A recognition system must evaluate the stability and collision rate of its actual test.

What does getBoundingClientRect include?

It encloses the element's border boxes, including padding and borders but excluding margins and ordinary overflowing children. CSS transforms affect the reported geometry, so its width and height need not equal the untransformed CSS dimensions.

What do the methods return for a hidden element?

For display:none, getClientRects returns no rectangles and getBoundingClientRect returns a zero rectangle. visibility:hidden and opacity:0 can still have measurable boxes. When boxes exist but all are empty, the bounding result uses the first box's position with zero dimensions.