Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

DOMRect.top — top-edge coordinate

`DOMRect.top` is a read-only property that returns the coordinate of a rectangle’s top edge. Even with a negative height, floating-point rounding can make the result equal to `y`.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

rect.top

DOMRect.top is an instance property inherited from DOMRectReadOnly. It returns a number describing the top-edge coordinate, not the rectangle’s height.

For finite y and height, it corresponds to Math.min(rect.y, rect.y + rect.height). With nonnegative height it equals y; with negative height, y + height.

top remains read-only on mutable DOMRect: change y or height, not top. The example changes the result from 30 to 50. This is a Web API, not an ECMAScript language feature; Node 24’s presence does not establish availability.

Examples

const rect = new DOMRect(10, 50, 80, -20);
console.log(rect.top);
rect.height = 20;
console.log(rect.top);

Result

30
50

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources