Favorites

DOM MouseEvent.button Property

☕
Enjoying this site?

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

Buy us a coffee
MouseEvent.button
DOM MouseEvent PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

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

Description

The read-only button property indicates which mouse button triggered a mousedown, mouseup or similar event. The "main" and "secondary" buttons are swapped for left-handed mouse settings. The buttons property (plural) gives a bit mask of every button currently held down.

For click events, button is always 0, since click only fires for the main button. The auxclick event fires for other buttons, such as a middle-click, and contextmenu fires for the secondary button or the keyboard's menu key.

Overriding the right-click menu prevents users from using familiar browser features, such as opening links in new tabs, so only do it when you provide a genuinely useful replacement, such as in a drawing or file-management app.

Syntax

event.button

Value

A number for the button that changed state: 0 main (usually left), 1 middle, 2 secondary (usually right), 3 back and 4 forward.

Example

<div id="pad" style="height:80px;background:#fef3c7;display:grid;place-items:center">Press any mouse button here</div>
const pad = document.getElementById('pad');
const names = ['main', 'middle', 'secondary', 'back', 'forward'];
pad.addEventListener('mousedown', e => console.log('button:', e.button, names[e.button]));
pad.addEventListener('contextmenu', e => e.preventDefault());

Browser Support

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

This property 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