MouseEvent.x is a read-only number and an alias for clientX: horizontal position inside the viewport. Learn why the short name exists, prove x === clientX, and practice with five try-it labs.
01
Kind
Instance property
02
Returns
Number (CSS px)
03
Status
Baseline Widely available
04
Alias of
clientX
05
Pair with
y / clientY
06
Origin
Viewport left edge
Fundamentals
Introduction
Some APIs like short names. event.x is simply another way to read the same viewport X that event.clientX already gives you. Pair it with event.y (alias of clientY) for a compact viewport point.
JavaScript
document.addEventListener("mousemove", (event) => {
console.log(event.x); // same as event.clientX
console.log(event.clientX); // viewport X in CSS pixels
});
💡
Beginner tip
MDN one-liner: MouseEvent.x is an alias for MouseEvent.clientX. If you already understand clientX, you already understand x.
Concept
Understanding the Property
MDN: the x property is an alias for clientX. That means it is the horizontal coordinate within the application’s viewport at which the event occurred—not the document page and not the OS screen.
Instance — read event.x in a handler.
Number — CSS pixels from the viewport’s left edge.
Alias — same value as event.clientX.
Read-only — set via constructor options (usually clientX) on synthetic events.
Foundation
📝 Syntax
JavaScript
const x = mouseEvent.x;
Value
A number in CSS pixels from the left edge of the viewport—identical to mouseEvent.clientX on supporting browsers.
MouseEvent.x is Baseline Widely available across modern browsers (MDN: since April 2017). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MouseEvent.x
Short alias for clientX—viewport X in CSS pixels for mouse events.
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
xExcellent
Bottom line: Read event.x or event.clientX for viewport X; they are the same value on supporting browsers.
Wrap Up
Conclusion
event.x is the short name for viewport X—an alias of clientX. Use either property for fixed UI and hit tests; reach for pageX when document scroll matters.
Use position: fixed overlays with viewport coordinates
Prefer one naming style in a codebase for consistency
Pass clientX in synthetic MouseEvent options
❌ Don’t
Assume x equals pageX after scrolling
Confuse viewport x with screen screenX
Mix x and clientX randomly in the same file
Use viewport coords for document-absolute markers
Mutate event.x on live user events
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about x
Short alias for clientX—viewport horizontal position.
5
Core concepts
🖱️01
Instance
on the event
Kind
🔄02
Alias
of clientX
MDN
📐03
Viewport
left edge origin
Origin
🔢04
Number
CSS pixels
Type
🛡️05
Baseline
widely available
Status
❓ Frequently Asked Questions
It is a read-only number that is an alias for MouseEvent.clientX: the horizontal mouse position in CSS pixels relative to the browser viewport (the visible window area).
No. MDN marks MouseEvent.x as Baseline Widely available (since April 2017). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
Yes. MDN states that MouseEvent.x is an alias for MouseEvent.clientX. In supporting browsers, event.x === event.clientX for the same event.
Both work. Many tutorials and codebases prefer clientX because the name clearly says “client/viewport.” Use x when you want shorter property names or CSSOM View-style naming next to event.y.
x / clientX are viewport-relative and ignore document scroll. pageX is document-relative and grows when you scroll right.
Pass clientX in MouseEvent options (for example new MouseEvent("click", { clientX: 120, clientY: 40 })). Engines typically expose the same value on event.x as well.
Did you know?
MouseEvent.x and MouseEvent.y come from the CSSOM View Module, which also defines many scrolling and layout measurement APIs. The short names make mouse coordinates feel more like a simple { x, y } point.