This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
The MouseEvent.buttons read-only property indicates which buttons are pressed on the mouse (or other input device) when a mouse event is triggered.
Each button that can be pressed is represented by a given number (see below). If more than one button is pressed, the button values are added together to produce a new number. For example, if the secondary (2) and auxiliary (4) buttons are pressed simultaneously, the value is 6 (i.e., 2 + 4).
Note: Do not confuse this property with the MouseEvent.button property. The MouseEvent.buttons property indicates the state of buttons pressed during any kind of mouse event, while the MouseEvent.button property only guarantees the correct value for mouse events caused by pressing or releasing one or multiple buttons.
A number representing one or more buttons. For more than one button pressed simultaneously, the values are combined (e.g., 3 is primary + secondary).
0: No button or un-initialized1: Primary button (usually the left button)2: Secondary button (usually the right button)4: Auxiliary button (usually the mouse wheel button or middle button)8: 4th button (typically the "Browser Back" button)16 : 5th button (typically the "Browser Forward" button)This example logs the buttons property when you trigger a mousedown event.
<p>Click anywhere with one or more mouse buttons.</p> <pre id="log">[No clicks yet]</pre>
const buttonNames = ["left", "right", "wheel", "back", "forward"];
function mouseButtonPressed(event, buttonName) {
// Use binary `&` with the relevant power of 2 to check if a given button is pressed
return Boolean(event.buttons & (1 << buttonNames.indexOf(buttonName)));
}
function format(event) {
const { type, buttons } = event;
const obj = { type, buttons };
for (const buttonName of buttonNames) {
obj[buttonName] = mouseButtonPressed(event, buttonName);
}
return JSON.stringify(obj, null, 2);
}
const log = document.getElementById("log");
function logButtons(event) {
log.textContent = format(event);
}
document.addEventListener("mouseup", logButtons);
document.addEventListener("mousedown", logButtons);
| Specification |
|---|
| UI Events> # dom-mouseevent-buttons> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
buttons |
43 | 12 | 15Restrictions apply depending on OS. |
30 | 11.1 | 43 | 15 | 30 | 11.3 | 4.0 | 43 | 11.3 |
Firefox supports the buttons attribute on Windows, Linux (GTK), and macOS with the following restrictions:
mouseup event always includes the releasing button information in the buttons value.buttons attribute always returns 0 because there is no platform API for implementing this feature.
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons