MouseEvent.buttons is a read-only bit-field: which mouse buttons are held when the event fires. Learn the power-of-two values, how to combine and test bits, how this differs from button, and five try-it labs.
01
Kind
Instance property
02
Returns
Number (bit-field)
03
Status
Baseline Widely available
04
Access
event.buttons
05
Check bit
& 1, & 2, & 4
06
Great for
Drag / mousemove
Fundamentals
Introduction
While drawing or dragging, you often need “is the left button still down?” on every mousemove. That is what buttons answers: the set of buttons currently pressed, encoded as a single number.
Think of sticky notes on a fridge: each button has its own note (1, 2, 4…). If several are stuck up, you add the numbers. To ask “is left up?” you use & with 1.
Concept
Understanding the Property
MDN: MouseEvent.buttons indicates which buttons are pressed when a mouse event is triggered. If more than one is pressed, the values are added together (for example secondary 2 + auxiliary 4 = 6).
Instance — read event.buttons in a handler.
Bit-field — powers of two that combine with addition / |.
Any mouse event — useful on mousemove, unlike button.
Not button — different property, different number system.
MouseEvent.buttons is Baseline Widely available across modern browsers (MDN: since April 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MouseEvent.buttons
Bit-field of held buttons for any mouse event—ideal for drag and paint on mousemove.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern IE versions
Full support
buttonsExcellent
Bottom line: Read event.buttons; test bits with &; prefer over button on mousemove.
Wrap Up
Conclusion
event.buttons is the held-button bit-field. Combine values when several buttons are down, test with &, and use it on mousemove for drag logic. Use button when you need which button just changed.
Treat remapped devices as logical primary/secondary
❌ Don’t
Confuse left buttons === 1 with button === 0
Expect button alone to drive drag painting
Compare buttons only with === 1 if chords matter
Forget 0 means no button held
Skip accessibility for pointer-only paint tools
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about buttons
Held-button bit-field for every mouse event type.
5
Core concepts
🖱️01
Instance
on the event
Kind
🔢02
1 / 2 / 4
left / right / mid
Bits
➕03
Add / OR
combine held
Chords
✏️04
Drag
on mousemove
Use
🛡️05
Baseline
since 2018
Status
❓ 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, so no status warning banner is needed.
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) === 1. 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.
Did you know?
MDN’s example uses 1 << index so left is bit 0 (1), right bit 1 (2), wheel bit 2 (4), and so on—the same powers of two listed in the value table, generated from an array of names.