JavaScript MouseEvent altKey Property

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

MouseEvent.altKey is a read-only boolean on each mouse event: true if Alt (Option on Mac) was held when the event fired. Learn how to read it, build Alt+click shortcuts, set it on synthetic events, and compare it with other modifiers.

01

Kind

Instance property

02

Returns

Boolean

03

Status

Baseline Widely available

04

Access

event.altKey

05

Mac name

Option key

06

Family

Modifier keys

Introduction

When a user clicks while holding a modifier key, your handler often needs a different action—for example Alt+click to open a detail panel. The browser stores that state on the event object as altKey.

On Mac keyboards this is the Option key. Same property name: event.altKey.

JavaScript
element.addEventListener("click", (event) => {
  console.log(event.altKey); // true or false
});
💡
Beginner tip

altKey is read from the event instance that arrived in your listener—not from the MouseEvent constructor itself (unlike the WebKit Force Touch statics).

Understanding the Property

MDN: MouseEvent.altKey is a read-only boolean that indicates whether the Alt key was pressed when a given mouse event occurred.

  • Instance — read event.altKey inside a handler.
  • Booleantrue pressed, false not pressed.
  • Read-only — you do not assign to it on a live user event.
  • Platform note — some Linux setups use Alt+click for window move/resize, so detection can fail.

📝 Syntax

JavaScript
const isAltHeld = mouseEvent.altKey;

Value

A boolean: true if Alt/Option was held during the event; otherwise false.

Setting it on synthetic events

JavaScript
const event = new MouseEvent("click", {
  altKey: true,
  bubbles: true
});
console.log(event.altKey); // true

⚖️ Related Modifier Properties

PropertyKeyTypical use
event.altKeyAlt / OptionAlt+click shortcuts
event.ctrlKeyControlMulti-select, open in new tab patterns
event.shiftKeyShiftRange select, alternate actions
event.metaKeyMeta / Command ⌘Mac Command-click patterns

You can also call event.getModifierState("Alt") for a related check when you want the KeyboardEvent-style modifier API.

⚡ Quick Reference

GoalCode
Read Alt stateevent.altKey
Alt+click branchif (event.altKey) { … }
Synthetic Alt clicknew MouseEvent("click", { altKey: true })
ModifierState APIevent.getModifierState("Alt")
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about altKey.

Kind
instance

On the event

Type
boolean

true / false

Status
baseline

Widely available

Mac
Option

Same property

Examples Gallery

Examples follow MDN MouseEvent.altKey. Hold Alt (Option on Mac) while clicking to see true.

📚 Getting Started

Read altKey from real click events.

Example 1 — Log altKey on Click

MDN-style demo: print whether Alt was held.

JavaScript
document.addEventListener("click", (e) => {
  console.log(`The alt key is pressed: ${e.altKey}`);
});
Try It Yourself

How It Works

Every click delivers a MouseEvent. Reading e.altKey tells you the Alt/Option state for that click only.

Example 2 — Branch on Alt+Click

Use a different action when Alt is held.

JavaScript
button.addEventListener("click", (e) => {
  if (e.altKey) {
    console.log("Alt+click — show advanced options");
  } else {
    console.log("Normal click — default action");
  }
});
Try It Yourself

How It Works

A simple if (e.altKey) is enough for most Alt+click shortcuts. Document the shortcut for users so they know it exists.

📈 Synthetic Events & Other Modifiers

Construct events in tests and compare modifier flags.

Example 3 — Synthetic Event with altKey: true

Great for unit tests without holding a physical key.

JavaScript
const event = new MouseEvent("click", {
  altKey: true,
  bubbles: true
});

console.log(event.altKey);     // true
console.log(event.type);       // "click"
console.log(event instanceof MouseEvent); // true
Try It Yourself

How It Works

The MouseEvent() constructor accepts modifier options. Dispatch the event if you need listeners to run.

Example 4 — Log All Modifier Keys

See Alt next to Ctrl, Shift, and Meta on the same event.

JavaScript
document.addEventListener("click", (e) => {
  console.log({
    altKey: e.altKey,
    ctrlKey: e.ctrlKey,
    shiftKey: e.shiftKey,
    metaKey: e.metaKey
  });
});
Try It Yourself

How It Works

All four flags are independent. Users can hold several at once (for example Ctrl+Alt+click).

Example 5 — altKey vs getModifierState("Alt")

Two ways to ask if Alt was active for the event.

JavaScript
const event = new MouseEvent("click", { altKey: true });

console.log(event.altKey);                 // true
console.log(event.getModifierState("Alt")); // true
console.log(event.altKey === event.getModifierState("Alt")); // true
Try It Yourself

How It Works

For everyday mouse handlers, event.altKey is clearer and shorter. getModifierState is handy when you already use that API for other keys.

🚀 Common Use Cases

  • Alt+click (Option+click) secondary actions in editors and dashboards.
  • Logging modifier state while debugging mouse handlers.
  • Unit tests that construct MouseEvent with altKey: true.
  • Combining with ctrlKey / shiftKey for multi-modifier shortcuts.
  • Teaching beginners the difference between instance modifiers and static Force Touch constants.

🔧 How It Works

1

User holds Alt / Option

The OS reports the modifier with the pointer action.

Input
2

Browser builds MouseEvent

Sets altKey to true or false.

Event
3

Listener receives the event

Your click / mousedown handler runs.

Handler
4

Branch on event.altKey

Choose default vs Alt+click behavior.

📝 Notes

Universal Browser Support

MouseEvent.altKey is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

MouseEvent.altKey

Reliable boolean for Alt/Option during mouse events. Still mind OS-level Alt+click conflicts on some Linux setups.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern IE versions
Full support
altKey Excellent

Bottom line: Read event.altKey in mouse handlers; set altKey in MouseEvent options for tests.

Conclusion

event.altKey tells you whether Alt/Option was held for that mouse event. Use it for Alt+click shortcuts, and set altKey on synthetic MouseEvent objects when testing.

Continue with button, MouseEvent(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read event.altKey inside the mouse handler
  • Document Alt/Option+click shortcuts for users
  • Test with new MouseEvent(..., { altKey: true })
  • Combine carefully with ctrlKey / shiftKey
  • Offer a non-modifier UI path when possible

❌ Don’t

  • Assume Alt+click always reaches the page on every Linux WM
  • Confuse instance altKey with WebKit static Force Touch constants
  • Rely only on hidden modifier shortcuts for critical actions
  • Forget Mac users know the key as Option
  • Mutate event.altKey on live user events

Key Takeaways

Knowledge Unlocked

Five things to remember about altKey

Boolean Alt/Option state on every mouse event.

5
Core concepts
02

Boolean

true / false

Type
🍎 03

Mac Option

same property

Platform
🔧 04

Synthetic OK

options.altKey

Tests
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only boolean on a mouse event that is true when the Alt key (Option on Mac) was held down at the time of that event, and false otherwise.
No. MDN marks MouseEvent.altKey as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
Yes. On Macintosh keyboards the Alt key is also called the Option key. MouseEvent.altKey reports that modifier.
MDN notes that some OSes reserve Alt+click for window move/resize, so the browser cannot always detect Alt during a mouse event. Treat Alt+click shortcuts carefully across platforms.
Pass altKey: true in the options object to new MouseEvent("click", { altKey: true }). The constructed event then reports event.altKey as true.
Mouse events also expose ctrlKey, shiftKey, and metaKey. Together they describe which modifier keys were held. You can also use event.getModifierState("Alt") for a related check.
Did you know?

MDN warns that on some Linux variants, Alt + left click is reserved for moving or resizing windows. Your page may never see that combination—so critical features should not depend on Alt+click alone.

Next: MouseEvent.button

Learn which mouse button changed on press and release events.

button →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful