The read-only buttons property is a bit-field number for which mouse buttons are held when the event fires (MDN). Multiple buttons add together (left 1 + right 2 = 3). Do not confuse it with button (which button just changed).
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use event.buttons. Start with this line.
JavaScript
event.buttons
Call
What it does
event.buttons
Primary signature.
Built into the browser. Read event.buttons on a MouseEvent — no import required.
Library declarations
JavaScript
event.buttons
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Number bit-field (0, 1, 2, 4, ...)
JavaScript Examples
Example 1 — Log buttons (MDN-style)
Print the bit-field on press and release.
JavaScript
function logButtons(event) {
console.log(event.type, event.buttons);
}
el.addEventListener("mousedown", logButtons);
el.addEventListener("mouseup", logButtons);
Also set button if your handler reads the changed-button property.
Compatibility
Browser Support
MouseEvent.buttons is marked Baseline Widely available on MDN (since April 2018).
✓ Baseline · Widely available
MouseEvent.buttons
Bit-field of held mouse buttons. Broader than button for drag/move. Safe everyday DOM API.
100%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
buttonsExcellent
Bottom line: Safe everyday API. Remember bits add (1+2=3). See the MDN buttons reference.
Frequently Asked Questions
It is a read-only number that is a bit-field of which mouse buttons are currently pressed when the event fires. Values add together—for example left (1) + right (2) = 3.
No. MDN marks MouseEvent.buttons as Baseline Widely available (since April 2018). It is not Deprecated, Experimental, or Non-standard.
button is which button changed (0 left, 1 middle, 2 right) and is reliable mainly on press/release events. buttons is which buttons are held (1 left, 2 right, 4 middle) and works across mouse event types, including mousemove.
Use a bitwise AND: (event.buttons & 1) !== 0. For right use & 2, for middle & 4.
Because bits add: secondary (2) + auxiliary/middle (4) = 6 when both are held at once.
Pass buttons in MouseEvent options, for example new MouseEvent("mousemove", { buttons: 1 }) to simulate left held while moving.