Favorites

DOM MouseEvent Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
MouseEvent
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

MouseEvent describes events caused by a mouse or other pointing device, such as click and mousemove, including the pointer position and which button was pressed.

Description

The MouseEvent interface represents events that occur because of the user interacting with a pointing device, such as click, dblclick, mousedown, mouseup, mousemove, mouseenter and contextmenu. It provides the pointer's position (clientX, pageX, offsetX and others), which button was used, and whether modifier keys such as Shift were held (shiftKey, ctrlKey, altKey, metaKey).

PointerEvent extends it to cover touch and pen input too, and is the better choice for new code that should work on every device.

The relatedTarget property is useful for mouseover, mouseout, mouseenter and mouseleave, where it identifies the element the pointer came from or moved to. Note that mouseenter and mouseleave don't bubble, while mouseover and mouseout do. On touch screens, browsers also send compatibility mouse events after a tap, so a single tap can trigger both touch and mouse handlers unless you use pointer events.

Inheritance

MouseEvent inherits properties and methods from Event.

Properties

NameDescription
MouseEvent.buttonThe button property tells you which mouse button was pressed or released: 0 for the main button, 1 for the middle and 2 for the secondary button.
MouseEvent.clientXThe clientX and clientY properties give the position of the mouse pointer when the event happened, relative to the viewport.

Example

<div id="box" style="height:80px;background:#eef2ff;display:grid;place-items:center">Move here</div>
const box = document.getElementById('box');
box.addEventListener('mousemove', e => {
  box.textContent = `x: ${e.offsetX}, y: ${e.offsetY}`;
});
box.addEventListener('click', e => console.log('clicked with shift?', e.shiftKey));
console.log('Move the mouse over the box');

Browser Support

The following information will show you the current browser support for the MouseEvent interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee