JavaScript MouseEvent movementX Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

MouseEvent.movementX is a read-only number: how far the pointer moved horizontally since the previous move event of the same type. Think current.screenX − previous.screenX.

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

Syntax

Use event.movementX. Start with this line.

JavaScript
event.movementX
CallWhat it does
event.movementXPrimary signature.

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

Library declarations
JavaScript
event.movementX

Parameters

ParameterDescription
Move eventRequired. mousemove, pointermove, or pointerrawupdate
DIY previous XOptional. Safer when pixel units must match

Return Value

Return ValueDescription
*The current value of event.movementX.

JavaScript Examples

Example 1 — Log movementX / movementY

MDN-style demo: print the delta while you move the mouse.

JavaScript
const log = document.getElementById("log");

document.addEventListener("mousemove", (event) => {
  log.textContent =
    `movement: ${event.movementX}, ${event.movementY}`;
});
Try It Yourself

How It Works

  1. Find the log node. getElementById("log") is where the text will appear.
  2. Listen for moves. Each mousemove delivers a fresh MouseEvent.
  3. Read both axes. movementX is horizontal; movementY is vertical.
  4. Update the UI. The template string replaces the log with the latest delta.

Example 2 — Zero on Non-Move Events

A plain click still has absolute coordinates, but movementX is 0.

JavaScript
document.addEventListener("click", (e) => {
  console.log({
    type: e.type,
    movementX: e.movementX, // 0
    clientX: e.clientX      // absolute position still set
  });
});
Try It Yourself

How It Works

  1. Listen for click. Clicks are mouse events, but not move events.
  2. Check the delta. MDN: movementX is always 0 here.
  3. Check absolute X. clientX still reports where you clicked.
  4. Rule of thumb. Need deltas? Use mousemove / pointermove, not click.

Example 3 — DIY Delta from screenX

MDN tip: compute your own delta when pixel units must stay consistent.

JavaScript
let prev = null;

document.addEventListener("mousemove", (e) => {
  const diyDx = prev == null ? 0 : e.screenX - prev;
  prev = e.screenX;

  console.log({
    movementX: e.movementX,
    diyDx
  });
});
Try It Yourself

How It Works

  1. Keep the last X. prev stores the previous screenX.
  2. First sample. When prev is null, treat the DIY delta as 0.
  3. Later samples. Subtract previous from current screenX to get diyDx.
  4. Compare. Log both the browser’s movementX and your DIY value — they are often close, but units can differ.

Browser Support

MouseEvent.movementX is Baseline Newly available (MDN: since January 2026). It is not Deprecated, Experimental, or Non-standard — but older browsers may need a DIY screenX fallback.

✓ Baseline · Newly available

MouseEvent.movementX

Horizontal pointer delta between consecutive move events — useful for pans, games, and relative input.

Modern Newly available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
movementX Good

Bottom line: Safe for modern evergreen browsers. For portable unit math, prefer successive screenX / clientX deltas as MDN recommends.

Frequently Asked Questions

It is a read-only number: the horizontal difference of the pointer between this move event and the previous move event of the same type. Conceptually: current.screenX − previous.screenX.
No. MDN marks MouseEvent.movementX as Baseline Newly available (since January 2026). It is not Deprecated, Experimental, or Non-standard. Older browsers may still need a DIY screenX fallback.
It is always zero on MouseEvent types other than mousemove, and on PointerEvent types other than pointermove or pointerrawupdate. A plain click reports 0 even though clientX may still update.
Browsers disagree on whether movementX uses physical pixels, logical pixels, or CSS pixels. For portable deltas, many apps compute their own delta from successive screenX or clientX values.
movementY is the vertical counterpart. Together they describe how far the pointer moved since the last move event of the same type.
Pointer-lock games, camera pans, drawing tools, and any UI that needs relative movement rather than absolute cursor position.

Next: MouseEvent.movementY

Learn the vertical pointer delta that pairs with movementX.

movementY 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.

11 people found this page helpful