# Get the center point of a DOMRect

Return [x, y] of the rect’s center.

Canonical: https://1loc.dev/dom/get-the-center-point-of-a-dom-rect/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function getCenter({ x, y, width, height }) { return [x + width / 2, y + height / 2]; }
```

## Input

```json
{
  "x": 0,
  "y": 0,
  "width": 200,
  "height": 400
}
```

## Expected output

```json
[
  100,
  200
]
```

## Edge case

Input:
```json
{
  "x": 10,
  "y": 10,
  "width": 0,
  "height": 0
}
```
Output:
```json
[
  10,
  10
]
```

## Limits

- Coordinates are in the rect’s own space: viewport pixels for getBoundingClientRect(). Add window.scrollX and scrollY for document coordinates.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/get-the-center-point-of-a-dom-rect.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Reads x and y so plain JSON rects work; runs in the lab. Original MDX retained as inert source evidence.
