JavaScript MouseEvent altKey Property

Beginner
5 min read
Updated: Nov 2026
5 examples
Property

Definition

The read-only altKey property is a boolean: true if Alt was held when the mouse event occurred, otherwise false (MDN). On Mac keyboards this is the Option key.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use event.altKey. Start with this line.

JavaScript
event.altKey
CallWhat it does
event.altKeyPrimary signature.

Built into the browser. Read event.altKey on a MouseEvent — no import required.

Library declarations
JavaScript
event.altKey

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*boolean

JavaScript Examples

Example 1 — Log altKey on Click

MDN-style: 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

  1. Listen for click. Each click delivers a MouseEvent.
  2. Read e.altKey. Boolean for Alt / Option.
  3. Log the value. Easy to verify in the console.
  4. Hold Alt and click again to see true.

Example 2 — Branch on Alt+Click

Common pattern: different action when Alt is held.

JavaScript
el.addEventListener("click", (e) => {
  if (e.altKey) {
    console.log("alt action");
  } else {
    console.log("normal action");
  }
});
Try It Yourself

How It Works

  1. Check e.altKey in the handler.
  2. true → Alt path. Alternate UI behavior.
  3. false → default path.
  4. Test on Linux if you ship Alt+click shortcuts.

Example 3 — Match getModifierState("Alt")

For Alt, the property and named API usually agree.

JavaScript
el.addEventListener("click", (e) => {
  console.log(e.altKey, e.getModifierState("Alt"));
});
Try It Yourself

How It Works

  1. Read altKey. Dedicated boolean.
  2. Call getModifierState("Alt"). Named check.
  3. Values match for normal Alt presses.
  4. Prefer altKey when you only need Alt/Option.

Example 4 — With Other Modifiers

Alt can combine with Ctrl, Shift, or Meta.

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

How It Works

  1. Read all four booleans from the same event.
  2. They are independent. Any mix can be true.
  3. Hold Alt+Shift (etc.) and click to see combos.
  4. Useful for power-user shortcuts.

Example 5 — Synthetic MouseEvent

Set altKey in constructor options for tests and scripts.

JavaScript
const e = new MouseEvent("click", { altKey: true });
console.log(e.altKey); // true
Try It Yourself

How It Works

  1. new MouseEvent with altKey: true.
  2. No real keyboard needed for the synthetic event.
  3. e.altKey is true.
  4. Handy in unit tests and scripted UI actions.

Browser Support

MouseEvent.altKey is marked Baseline Widely available on MDN (since July 2015).

✓ Baseline · Widely available

MouseEvent.altKey

Boolean: true if Alt (Option on Mac) was held during the mouse event. Some OSes may intercept Alt+click.

100% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
altKey Excellent

Bottom line: Safe everyday API. Prefer altKey for Alt/Option; test Alt+click on Linux desktops. See the MDN altKey reference.

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.
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.
event.getModifierState("Alt") is a related check. For everyday Alt/Option, event.altKey is clearer and enough.

Next: button

Learn which mouse button produced the event.

button tutorial →

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.

8 people found this page helpful