MouseEvent.pageX is a read-only number: the mouse’s horizontal position relative to the entire document, including scrolled-away content. Learn how it differs from clientX and offsetX, the scroll formula, and five try-it labs.
01
Kind
Instance property
02
Returns
Number (CSS px)
03
Status
Baseline Widely available
04
Origin
Document left edge
05
Pair with
pageY
06
Scroll
Included in the value
Fundamentals
Introduction
Absolute-positioned pins, annotations on a long page, and document-space hit maps need “where on the page?” That is pageX (horizontal) and pageY (vertical)—coordinates relative to the whole document, not just the visible window.
JavaScript
document.addEventListener("mousemove", (event) => {
console.log(event.pageX); // pixels from document left (includes scroll)
});
💡
Beginner tip
MDN: if 200px of the left side is scrolled out of view and you click 100px from the viewport’s left edge, pageX is 300.
Concept
Understanding the Property
MDN: pageX returns the X (horizontal) coordinate (in pixels) at which the mouse was clicked, relative to the left edge of the entire document. This includes any portion of the document not currently visible.
Instance — read event.pageX in a handler.
Number — CSS pixels; a floating-point double.
Document-relative — includes horizontal scroll.
Read-only — set via constructor options on synthetic events only.
Foundation
📝 Syntax
JavaScript
const x = mouseEvent.pageX;
Value
A double floating-point number of pixels from the left edge of the document (MDN), regardless of scrolling or viewport positioning. Originally specified as a long integer; CSSOM View redefined it as a double for subpixel precision.
MouseEvent.pageX is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MouseEvent.pageX
Reliable document-relative X including horizontal scroll—great for absolute page markers.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern IE versions
Full support
pageXExcellent
Bottom line: Read event.pageX for document-space horizontal position; pair with pageY for a full document point.
Wrap Up
Conclusion
event.pageX gives you the horizontal mouse position relative to the entire document, including scrolled content. Use it for absolute page markers; reach for clientX for viewport UI and offsetX for element-local clicks.
Use absolute positioning when placing page markers
Prefer clientX for position: fixed UI
❌ Don’t
Confuse pageX with viewport clientX
Ignore horizontal scroll when debugging large pageX values
Use page coordinates for fixed tooltips without converting
Assume it equals offsetX inside an element
Mutate event.pageX on live user events
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about pageX
Document-relative X that includes horizontal scroll.
5
Core concepts
🖱️01
Instance
on the event
Kind
🔢02
Double
CSS pixels
Type
📄03
Document
left edge origin
Origin
📈04
Scroll-aware
+ scrollX
Math
🛡️05
Baseline
widely available
Status
❓ Frequently Asked Questions
It is a read-only number: the horizontal mouse position in CSS pixels relative to the left edge of the entire document, including any part of the page that is scrolled out of view.
No. MDN marks MouseEvent.pageX as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
pageX includes horizontal scroll. MDN’s example: if 200px of the left side is scrolled away and you click 100px from the viewport’s left edge, pageX is 300.
clientX is relative to the viewport (window) and ignores document scroll. pageX is relative to the document and grows when you scroll right. Often: pageX ≈ clientX + window.scrollX.
offsetX is relative to the target element’s padding edge. pageX is relative to the whole document. Use offsetX for clicks inside a box; use pageX for markers on a scrolled page.
A double floating-point number of pixels. It was originally defined as a long integer; the CSSOM View Module redefined it as a double for subpixel precision.
Did you know?
MDN notes that pageX was originally specified as a long integer in the Touch Events world, then redefined in the CSSOM View Module as a double for subpixel precision. Both still show up as JavaScript Number, but engines may handle them differently under the hood.