JavaScript MouseEvent metaKey Property

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

What You’ll Learn

MouseEvent.metaKey is a read-only boolean: true if the Meta key was held when the mouse event fired. Learn Command vs Windows-key mapping, OS shortcut caveats, Command+click patterns, synthetic events, and five try-it labs.

01

Kind

Instance property

02

Returns

Boolean

03

Status

Baseline Widely available

04

Access

event.metaKey

05

Mac / Win

⌘ / ⊞

06

Family

modifier keys

Introduction

On Mac, Command+click is the familiar “open related” / multi-select pattern. That key state is exposed as metaKey. On Windows, the same property tracks the Windows key—but the OS often claims that key for itself.

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

MDN: on Macintosh keyboards Meta is Command (⌘); on Windows keyboards it is the Windows key (⊞). Many OSes bind special actions to Meta, so metaKey may stay false even while the key is pressed (for example opening the Start menu on Windows).

Understanding the Property

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

  • Instance — read event.metaKey inside a handler.
  • Booleantrue pressed, false not pressed.
  • Read-only — set via constructor options on synthetic events.
  • OS may intercept — Meta often triggers system UI before your page sees it.

📝 Syntax

JavaScript
const isMetaHeld = mouseEvent.metaKey;

Value

A boolean: true if Meta was held during the event; otherwise false.

Setting it on synthetic events

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

⚖️ Related Modifier Properties

PropertyKeyTypical use
event.metaKeyMeta / Command ⌘ / Win ⊞Mac Command-click; Meta-aware shortcuts
event.ctrlKeyControlCtrl+click on Windows/Linux
event.altKeyAlt / OptionAlt+click shortcuts
event.shiftKeyShiftRange select, alternate actions

You can also call event.getModifierState("Meta") for a related check.

⚡ Quick Reference

GoalCode
Read Meta stateevent.metaKey
Command+click branchif (event.metaKey) { … }
Cross-platform power-clickif (event.ctrlKey || event.metaKey)
Synthetic Meta clicknew MouseEvent("click", { metaKey: true })
modifierState APIevent.getModifierState("Meta")
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about metaKey.

Kind
instance

On the event

Type
boolean

true / false

Status
baseline

Widely available

Keys
⌘ / ⊞

Command / Windows

Examples Gallery

Examples follow MDN MouseEvent.metaKey. Hold (Mac) or try Meta on your platform while clicking to see true (OS caveats apply).

📚 Getting Started

Read metaKey from real pointer events.

Example 1 — Log metaKey on Click

MDN-style demo: print whether Meta was held when you clicked.

JavaScript
const log = document.querySelector("#log");

document.addEventListener("click", (e) => {
  log.textContent = `The meta key is pressed: ${e.metaKey}`;
});
Try It Yourself

How It Works

Each click updates the log from e.metaKey. Hold Command on Mac while clicking to see true. On Windows, the Windows key may never reach the page.

Example 2 — Branch on Meta / Ctrl+Click

Use a secondary action for Command (Mac) or Control (Windows/Linux).

JavaScript
link.addEventListener("click", (e) => {
  if (e.metaKey || e.ctrlKey) {
    // Command (Mac) or Control (Win/Linux)
    console.log("modifier+click — open related view");
    return;
  }
  console.log("Normal click — default action");
});
Try It Yourself

How It Works

Checking metaKey || ctrlKey covers Command on Mac and Control on Windows/Linux for many “power click” UX patterns.

📈 Synthetic Events & Other Modifiers

Construct events in tests and compare modifier flags.

Example 3 — Synthetic Event with metaKey: true

Great for unit tests without holding a physical key.

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

console.log(event.metaKey);     // 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 Meta next to Control, Alt, and Shift on the same event.

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

How It Works

All four flags are independent. Users can hold several at once (for example Command+Shift+click on Mac).

Example 5 — metaKey vs getModifierState("Meta")

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

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

console.log(event.metaKey);                   // true
console.log(event.getModifierState("Meta"));   // true
console.log(event.metaKey === event.getModifierState("Meta")); // true
Try It Yourself

How It Works

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

🚀 Common Use Cases

  • Command+click secondary actions and multi-select on Mac.
  • Cross-platform power-clicks with metaKey || ctrlKey.
  • Unit tests that construct MouseEvent with metaKey: true.
  • Detecting Meta-aware shortcuts (when the OS does not steal the key).
  • Teaching the modifier family next to ctrlKey and altKey.

🔧 How It Works

1

User holds Meta

Command on Mac, or Windows key on Windows (if not OS-stolen).

Input
2

Browser builds MouseEvent

Sets metaKey to true or false.

Event
3

Listener receives the event

Your click / mousedown handler runs.

Handler
4

Branch on event.metaKey

Choose default vs Meta-modified behavior.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Mac Meta = Command (⌘); Windows Meta = Windows key (⊞).
  • OS shortcuts may keep metaKey false even when the key is held.
  • Related: layerY, movementX, ctrlKey, altKey, MouseEvent(), Window, JavaScript hub.

Universal Browser Support

MouseEvent.metaKey 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.metaKey

Reliable Meta modifier boolean—Command on Mac, Windows key on Windows (OS may intercept).

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
metaKey Excellent

Bottom line: Read event.metaKey in mouse handlers; pair with ctrlKey for cross-platform power-clicks.

Conclusion

event.metaKey tells you whether Meta was held for that mouse event—Command on Mac, Windows key on Windows. Use it for Command+click shortcuts, pair with ctrlKey for cross-platform power-clicks, and set metaKey on synthetic MouseEvent objects when testing.

Continue with movementX, ctrlKey, altKey, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read event.metaKey inside the mouse handler
  • Use metaKey || ctrlKey for cross-platform power-clicks
  • Test with new MouseEvent(..., { metaKey: true })
  • Remember Command (Mac) vs Windows key mapping
  • Offer a non-modifier UI path when possible

❌ Don’t

  • Assume the Windows key always reaches your page
  • Confuse Meta/Command with Control (ctrlKey)
  • Rely only on hidden modifier shortcuts for critical actions
  • Treat Meta as identical on every OS without testing
  • Mutate event.metaKey on live user events

Key Takeaways

Knowledge Unlocked

Five things to remember about metaKey

Boolean Meta / Command / Windows-key state on mouse events.

5
Core concepts
02

Boolean

true / false

Type
🍎 03

⌘ / ⊞

Command / Win

Platform
🔧 04

Synthetic OK

options.metaKey

Tests
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only boolean on a mouse event that is true when the Meta key was held down at the time of that event, and false otherwise. On Mac that is usually Command (⌘); on Windows it is the Windows key (⊞).
No. MDN marks MouseEvent.metaKey as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
On Macintosh keyboards it is the Command key (⌘). On Windows keyboards it is the Windows key (⊞). Other platforms may map Meta differently.
MDN notes that many operating systems bind special functionality to the Meta key (for example opening the Start menu on Windows), so the property may stay false even when the key is physically pressed.
Pass metaKey: true in the options object to new MouseEvent("click", { metaKey: true }). The constructed event then reports event.metaKey as true.
They are different modifiers. Mac power-clicks often use Command (metaKey); Windows/Linux often use Control (ctrlKey). Checking ctrlKey || metaKey covers both platforms for many secondary-click patterns. You can also use event.getModifierState("Meta").
Did you know?

MDN warns that many operating systems bind special functionality to the Meta key, so metaKey may be false even when the key is actually pressed. On Windows, for example, that key may open the Start menu before your page ever sees the event—so always provide a non-Meta way to reach important actions.

Next: MouseEvent.movementX

Learn horizontal pointer deltas between consecutive move events.

movementX →

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