MouseEvent clientX Property
Example
The coordinates of the mouse pointer when clicked:
let x = event.clientX; // Horizontal
let y = event.clientY; // Vertical
Try it Yourself »
More examples below.
Description
The clientX
property returns the horizontal client coordinate of the mouse pointer when a mouse event
occurs.
The clientX
property is read-only.
The client area is the current window.
Coordinate Properties
Property | Relative to |
---|---|
The screenX Property | The Screen area |
The screenY Property | The Screen area |
The clientX Property | The Window area |
The clientY Property | The Window area |
The pageX Property | The Page (Document) |
The pageY Property | The Page (Document) |
The offsetX Property | The target Element |
The offsetY Property | The target Element |
See Also:
Syntax
event.clientX
Technical Details
Return Value: |
A Number. The horizontal window pixel coordinate of the mouse pointer. |
---|---|
DOM Version: | DOM Level 2 Mouse Events. |
More Examples
Example
The coordinates of the mouse pointer while the mouse pointer moves:
let x = event.clientX;
let y = event.clientY;
Try it Yourself »
Example
The differences between clientX and clientY and screenX and screenY:
let cX = event.clientX;
let cY = event.clientY;
let sX = event.screenX;
let sY = event.screenY;
Try it Yourself »
Browser Support
event.clientX
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |