event.pageX is a Number property with the pointer’s horizontal position relative to the document’s left edge — scroll included. This tutorial covers the official mousemove demo, pairing with pageY, comparing with clientX, click pins, and drag tracking.
01
Property
event.pageX
02
Returns
Number (px)
03
Official
mousemove log
04
Document
Left edge
05
pageY
Vertical pair
06
Since 1.0.4
Mouse events
Fundamentals
Introduction
When the user moves or clicks the mouse, you often need to know where the pointer was. jQuery forwards coordinate properties from the browser on its event object — including event.pageX for horizontal document position.
Unlike viewport coordinates (clientX), pageX counts pixels from the left edge of the full document, so it stays consistent when the page is scrolled vertically or horizontally. jQuery has exposed it since version 1.0.4.
Concept
Understanding event.pageX
This property answers one question: how far right is the pointer from the document’s left edge?
Origin — left edge of the document (not the viewport, not the clicked element).
Includes scroll — horizontal scroll offset is included in the value.
Read-only — a Number in pixels; not a method.
Pair with pageY — use both for full document coordinates.
💡
Beginner Tip
Think of the document as a large canvas. pageX is how many pixels from the canvas left border the mouse sits — even if you scrolled the window to see a different part of that canvas.
Click anywhere → pin moves to (pageX, pageY)
#coords shows "Pinned at pageX: …"
How It Works
Absolutely positioned elements use document coordinates when position: absolute relative to the document body — pageX maps directly to left.
📈 Practical Patterns
Scroll comparison, drag, and HUD readouts.
Example 3 — Scrolled page: pageX vs clientX
Log both coordinates — after scrolling, pageX and clientX diverge horizontally when the page has horizontal scroll (or use vertical scroll to see pageY vs clientY).
Charts and maps often map pageX (adjusted by element offset) to data values — the HUD demonstrates live horizontal document position.
Applications
🚀 Common Use Cases
Coordinate display — show pointer X/Y in debugging HUDs.
Image annotation — place pins at click pageX / pageY.
Drag and drop — compute movement deltas with page coordinates.
Drawing apps — line tools using document-space points.
Heatmaps — log click positions for analytics.
Custom sliders — map horizontal pageX to value ranges.
🧠 How pageX Works
1
Pointer event
User moves or clicks — browser fires mousemove, click, etc.
Event
2
Browser computes
Native event gets pageX from viewport position plus scroll offsets.
Native
3
jQuery handler
Your .on() callback reads event.pageX as a Number.
Read
4
✓
Position UI
Place markers, drag elements, or map X to data — scroll-aware document space.
Important
📝 Notes
Available since jQuery 1.0.4 — returns a Number (pixels).
Read-only property on mouse events.
Relative to the document left edge, not the clicked element.
Always pair with pageY for 2D document coordinates.
Use clientX for fixed viewport overlays; offsetX for local element coords.
jQuery normalizes coordinates consistently across supported browsers.
Compatibility
Browser Support
event.pageX is forwarded on jQuery’s event object since jQuery 1.0.4+ for mouse events. Underlying values come from the DOM MouseEvent pageX property — supported in all browsers jQuery targets.
✓ jQuery 1.0.4+ · all browsers
jQuery event.pageX
Horizontal pointer position in document space.
100%Universal
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
pageXNumber (px)
Bottom line: Read event.pageX on mousemove or click — document left edge origin.
Wrap Up
Conclusion
event.pageX gives the pointer’s horizontal distance from the document’s left edge — the official demo logs it alongside pageY on mousemove.
Use it for scroll-stable positioning, drag deltas, and click annotations — and choose clientX or offsetX when your reference frame is the viewport or a single element.
Compute drag deltas with differences of pageX readings
Round for display: Math.round(event.pageX)
Subtract element offset when mapping to local chart data
Prefer page coords when the page may scroll during interaction
❌ Don’t
Call event.pageX() with parentheses
Confuse pageX with clientX after scrolling
Use pageX on keyboard-only events for pointer position
Assume pageX is relative to the clicked child — use offsetX
Assign to event.pageX — it is read-only
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about pageX
Document horizontal mouse coordinate.
5
Core concepts
X01
pageX
Number (px)
API
doc02
Document
Left edge
Origin
demo03
Official
mousemove
Demo
Y04
pageY
Vertical pair
Pair
vs05
clientX
Viewport
Compare
❓ Frequently Asked Questions
event.pageX is a Number property on the jQuery event object. It returns the mouse pointer's horizontal coordinate relative to the left edge of the document — including scrolled content. Available since jQuery 1.0.4 on mouse events such as mousemove, click, and mousedown.
clientX is relative to the browser viewport (visible window). pageX includes horizontal scroll offset — pageX equals clientX plus the document's horizontal scroll. Use pageX when you need document-wide coordinates; clientX for viewport-fixed UI like tooltips.
pageX is horizontal (distance from the document's left edge). pageY is vertical (distance from the document's top edge). Together they give a full (x, y) point in document space — the official jQuery demo logs both on mousemove.
Mouse events expose pageX — including mousemove, mouseenter, mouseleave, mouseover, mouseout, mousedown, mouseup, and click. Keyboard events do not have meaningful pageX values for pointer position.
No. pageX is read-only — the browser sets it from the pointer position when the event fires. To move UI, read pageX and apply the value to your own variables or CSS.
pageX is relative to the entire document. offsetX is relative to the event target element's padding edge. Use pageX for absolute document positioning (pins on a map); offsetX for clicks inside a specific box.
Did you know?
Before unified pointer events, cross-browser mouse coordinates were painful — jQuery has forwarded pageX and pageY since 1.0.4 so plugins could rely on one document-space API. The names mirror the DOM MouseEvent properties exactly.