JavaScript MouseEvent x Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

MouseEvent.x is a read-only number: the mouse’s horizontal position in CSS pixels, measured from the viewport left edge. Per MDN, it is an alias for clientX.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use event.x. Start with this line.

JavaScript
const x = mouseEvent.x;
CallWhat it does
const x = mouseEvent.x;Primary signature.

Built into the browser. Read event.x on a MouseEvent — no import required.

Library declarations
JavaScript
const x = mouseEvent.x;

Parameters

ParameterDescription
Mouse / pointer eventRequired. Source that exposes x

Return Value

Return ValueDescription
*The current value of event.x.

JavaScript Examples

Example 1 — Read x on Move

Print viewport X and Y while the mouse moves.

JavaScript
document.addEventListener("mousemove", (event) => {
  console.log(event.x, event.y);
});
Try It Yourself

How It Works

  1. Listen for moves. Every pointer move fires mousemove.
  2. Read the short names. event.x / event.y are viewport coordinates.
  3. Same as client. Values match clientX / clientY.
  4. Use the numbers. Great for fixed UI, tooltips, and simple hit tests.

Example 2 — Prove x === clientX

Confirm MDN’s alias rule with a one-line equality check.

JavaScript
document.addEventListener("click", (event) => {
  console.log(event.x);
  console.log(event.clientX);
  console.log(event.x === event.clientX);
});
Try It Yourself

How It Works

  1. Click once. The handler runs with a real MouseEvent.
  2. Print both names. x and clientX show the same number.
  3. Compare with ===. true means the alias works in this browser.
  4. Pick one style. Keep x or clientX consistent in your project.

Example 3 — x vs pageX

See when viewport X and document X stay equal — and when they diverge.

JavaScript
document.addEventListener("click", (event) => {
  console.log({
    x: event.x,
    clientX: event.clientX,
    pageX: event.pageX,
    scrollX: window.scrollX
  });
});
Try It Yourself

How It Works

  1. Alias pair first. x and clientX stay locked together.
  2. Check scroll. With scrollX === 0, pageX matches too.
  3. Scroll horizontally. pageX grows; x stays viewport-based.
  4. Rule of thumb. Fixed overlays → x; document markers → pageX.

Browser & Runtime Support

MouseEvent.x is Baseline Widely available (MDN: since April 2017). It is defined in the CSSOM View Module as an alias of clientX.

✓ Baseline · Widely available

MouseEvent.x

Supported across modern Chrome, Firefox, Safari, and Edge. Same practical availability as clientX for viewport X.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
MouseEvent.x Excellent

Bottom line: Safe for production. Prefer clientX if your team wants the longer, more explicit name; values match on supporting browsers.

Frequently Asked Questions

It is a read-only number: the horizontal mouse position in CSS pixels relative to the browser viewport. MDN documents it as an alias for MouseEvent.clientX.
No. MDN marks MouseEvent.x as Baseline Widely available (since April 2017). It is not Deprecated, Experimental, or Non-standard.
Yes. On supporting browsers, event.x === event.clientX for the same event. Prefer one naming style in a codebase.
x / clientX are measured from the viewport’s left edge and ignore document scroll. pageX is measured from the document’s left edge and grows when you scroll right.
screenX is relative to the entire screen (monitor). x is relative to the browser viewport only.
Pass clientX in MouseEvent options, for example new MouseEvent("click", { clientX: 120, clientY: 40 }). Engines typically expose the same value on event.x.

Next: y

Learn the short alias for clientY — viewport vertical coordinates.

y tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful