Favorites

DOM MouseEvent.clientX Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
MouseEvent.clientX
DOM MouseEvent PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The clientX and clientY properties give the position of the mouse pointer when the event happened, relative to the viewport.

Description

The read-only clientX and clientY properties give the pointer's coordinates within the viewport at the time of the event, unaffected by scrolling. Related properties give other reference points: pageX/pageY relative to the whole document, offsetX/offsetY relative to the target element, and screenX/screenY relative to the screen.

Because they're relative to the viewport, clientX and clientY match the coordinates used by getBoundingClientRect(), making it easy to work out where inside an element the pointer is: e.clientX - rect.left.

For dragging, listen for pointermove rather than mousemove, so the same code works with touch and pen input, and call setPointerCapture() on the dragged element so it keeps receiving events even if the pointer moves outside it.

Syntax

event.clientX
event.clientY

Value

The horizontal (or vertical) pointer position in pixels, relative to the viewport.

Example

<div id="area" style="height:100px;background:#f1f5f9;display:grid;place-items:center">Move the pointer here</div>
const area = document.getElementById('area');
area.addEventListener('pointermove', e => {
  area.textContent = `clientX: ${e.clientX}, clientY: ${e.clientY}`;
});

Browser Support

The following information will show you the current browser support for the MouseEvent.clientX property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee