The mousemove event fires when a pointing device moves inside an element. Learn addEventListener vs onmousemove, coordinates, movementX/movementY, canvas drawing with mousedown/mouseup, performance tips, and five try-it labs.
01
Kind
Instance event
02
Type
MouseEvent
03
When
Pointer moves
04
Handler
onmousemove
05
Rate
Can be very high
06
Status
Baseline widely available
Fundamentals
Introduction
mousemove answers: “Did the pointer just move while over this element?” It fires whether or not buttons are pressed, and it can fire extremely often while the user is moving.
That high rate makes it perfect for drawing, custom cursors, and drag tracking— and also easy to misuse. Keep handlers cheap, or only process moves while a drag/draw flag is true.
💡
Beginner tip
For canvas drawing, MDN pairs mousedown (start), mousemove (draw while active), and mouseup on window (stop even if the pointer leaves the canvas).
Concept
Understanding mousemove
An instance event that answers: “Did the pointer move here?”
Fires when the pointer moves while inside the element.
Buttons optional — moves fire even with no button down.
MouseEvent — coordinates, movement deltas, and buttons.
High rate — depends on mouse speed, device, and system load.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
mousemove is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Coordinate and movement fields are supported across modern engines.
✓ Baseline · Widely available
Element mousemove
Fires when the pointer moves inside an element; pair with mousedown/mouseup for drawing and drag.
FullWidely available
Google ChromeFull support
Yes
Mozilla FirefoxFull support
Yes
Apple SafariFull support
Yes
Microsoft EdgeFull support
Yes
OperaFull support
Yes
Internet ExplorerSupported
Yes
mousemoveBaseline
Bottom line: Safe and universal. Treat fire rate carefully, and prefer pointer events for multi-input drag UX.
Wrap Up
Conclusion
mousemove is the continuous “pointer moved” signal. Use it for drawing and drag tracking, keep handlers light, and pair it with mousedown / mouseup for session start and stop.
Gate move work behind a drag/draw flag when possible
Use offsetX/offsetY for element-local drawing
Listen for mouseup on window to end strokes
Throttle heavy UI with requestAnimationFrame
Prefer addEventListener in production code
❌ Don’t
Do expensive DOM work on every raw mousemove
Forget that moves fire even with no button pressed
Assume release always happens over the same element
Ignore touch/pen if your app needs them—consider pointer events
Overwrite onmousemove if you need multiple listeners
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about mousemove
Pointer moved—often, fast, and useful for draw/drag.
5
Core concepts
📱01
On move
fires repeatedly
Trigger
📄02
MouseEvent
coords · deltas
API
👆03
High rate
keep handlers light
Perf
🔄04
mousedown/up
draw/drag session
Pair
🎯05
Baseline
widely available
Status
❓ Frequently Asked Questions
It fires when a pointing device moves while its hotspot is inside the element. It can fire whether or not any mouse buttons are pressed.
No. MDN marks Element mousemove as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A MouseEvent (inherits from UIEvent and Event). Useful fields include clientX, clientY, offsetX, offsetY, movementX, movementY, and buttons.
It can fire at a very high rate depending on mouse speed, machine speed, and other work. Keep handlers light, throttle updates, or only track while dragging.
Use mousedown to start, mousemove to draw while a flag is true, and mouseup (often on window) to stop — the MDN canvas pattern.
For unified mouse/touch/pen tracking, Pointer Events (pointermove) plus setPointerCapture are often a better modern model. mousemove remains widely used for mouse-only demos.
Did you know?
movementX and movementY report motion since the previous mousemove, which is perfect for relative controls—even when absolute screen position is less important.