clientX vs pageX vs screenX vs offsetX in JavaScript

When handling mouse events in JavaScript, determining the exact location of a cursor click or movement requires choosing the right coordinate property. While clientX, pageX, screenX, and offsetX all return horizontal pixel coordinates (with matching Y counterparts for vertical measurements), they differ based on their point of origin. This article breaks down each property’s specific reference frame so you can accurately position UI elements, track interactions, and manage layouts.

clientX / clientY: Relative to the Viewport

clientX and clientY measure the mouse pointer’s position relative to the visible area of the browser window (the viewport).

pageX / pageY: Relative to the Entire Document

pageX and pageY provide coordinates measured relative to the entire HTML document.

screenX / screenY: Relative to the Physical Monitor

screenX and screenY measure coordinates relative to the user’s physical display screen.

offsetX / offsetY: Relative to the Target Element

offsetX and offsetY measure the pointer position relative to the specific HTML element that triggered the event.

Summary Comparison

Property Reference Frame (0, 0 Origin) Affected by Page Scroll?
clientX / clientY Top-left corner of the browser viewport No
pageX / pageY Top-left corner of the HTML document Yes
screenX / screenY Top-left corner of the physical monitor No
offsetX / offsetY Top-left corner of the target element No