JavaScript MouseEvent shiftKey Property

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

What You’ll Learn

MouseEvent.shiftKey is a read-only boolean: true if Shift was held when the mouse event fired. Learn Shift+click patterns, how it sits next to other modifiers, synthetic events, and five try-it labs.

01

Kind

Instance property

02

Returns

Boolean

03

Status

Baseline Widely available

04

Access

event.shiftKey

05

Key

Shift ⇧

06

Family

modifier keys

Introduction

Shift+click is a classic “extend selection” / alternate-action pattern in lists, file pickers, and toolbars. That key state is exposed as shiftKey on every mouse event.

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

Hold Shift and click in a try-it lab. The property becomes true for that click only—release Shift and the next click is false again.

Understanding the Property

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

  • Instance — read event.shiftKey inside a handler.
  • Booleantrue pressed, false not pressed.
  • Read-only — set via constructor options on synthetic events.
  • Independent — works alongside Ctrl, Alt, and Meta flags.

📝 Syntax

JavaScript
const isShiftHeld = mouseEvent.shiftKey;

Value

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

Setting it on synthetic events

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

⚖️ Related Modifier Properties

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

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

⚡ Quick Reference

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

🔍 At a Glance

Four facts about shiftKey.

Kind
instance

On the event

Type
boolean

true / false

Status
baseline

Widely available

Key
Shift

Either Shift key

Examples Gallery

Examples follow MDN MouseEvent.shiftKey. Hold Shift while clicking to see true.

📚 Getting Started

Read shiftKey from real pointer events.

Example 1 — Log shiftKey on Click

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

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

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

How It Works

Each click updates the log from e.shiftKey. Hold Shift while clicking to see true.

Example 2 — Branch on Shift+Click

Use a secondary action when Shift is held (range-select style).

JavaScript
item.addEventListener("click", (e) => {
  if (e.shiftKey) {
    console.log("Shift+click — extend selection");
    return;
  }
  console.log("Normal click — select one item");
});
Try It Yourself

How It Works

A simple if (e.shiftKey) branch lets one click handler support both single-select and “extend selection” behavior.

📈 Synthetic Events & Other Modifiers

Construct events in tests and compare modifier flags.

Example 3 — Synthetic Event with shiftKey: true

Great for unit tests without holding a physical key.

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

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

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

How It Works

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

Example 5 — shiftKey vs getModifierState("Shift")

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

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

console.log(event.shiftKey);                    // true
console.log(event.getModifierState("Shift"));    // true
console.log(event.shiftKey === event.getModifierState("Shift")); // true
Try It Yourself

How It Works

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

🚀 Common Use Cases

  • Shift+click range selection in lists, tables, and file trees.
  • Alternate toolbar or canvas actions while Shift is held.
  • Unit tests that construct MouseEvent with shiftKey: true.
  • Combining Shift with ctrlKey or metaKey for multi-modifier shortcuts.
  • Teaching the modifier family next to Alt and Meta.

🔧 How It Works

1

User holds Shift

Left or right Shift counts the same for this property.

Input
2

Browser builds MouseEvent

Sets shiftKey to true or false.

Event
3

Listener receives the event

Your click / mousedown handler runs.

Handler
4

Branch on event.shiftKey

Choose default vs Shift-modified behavior.

📝 Notes

Universal Browser Support

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

Reliable Shift modifier boolean for mouse events—great for range-select and alternate clicks.

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

Bottom line: Read event.shiftKey in mouse handlers; use Shift+click for extend-selection and alternate actions.

Conclusion

event.shiftKey tells you whether Shift was held for that mouse event. Use it for Shift+click range selection and alternate actions, and set shiftKey on synthetic MouseEvent objects when testing.

Continue with screenY, webkitForce, ctrlKey, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read event.shiftKey inside the mouse handler
  • Use Shift+click for extend-selection patterns
  • Test with new MouseEvent(..., { shiftKey: true })
  • Document Shift shortcuts in your UI when they matter
  • Offer a non-modifier path for critical actions

❌ Don’t

  • Confuse Shift with Control or Meta
  • Assume left and right Shift need separate handling here
  • Rely only on hidden Shift shortcuts for critical actions
  • Forget that modifiers can combine (Shift+Ctrl+click)
  • Mutate event.shiftKey on live user events

Key Takeaways

Knowledge Unlocked

Five things to remember about shiftKey

Boolean Shift key state on mouse events.

5
Core concepts
02

Boolean

true / false

Type
03

Shift

either key

Key
🔧 04

Synthetic OK

options.shiftKey

Tests
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only boolean on a mouse event that is true when the Shift key was held down at the time of that event, and false otherwise.
No. MDN marks MouseEvent.shiftKey as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
Range selection in lists and file trees, alternate toolbar actions, and “extend selection” UX. Your handler can branch with if (event.shiftKey) { … }.
Pass shiftKey: true in the options object to new MouseEvent("click", { shiftKey: true }). The constructed event then reports event.shiftKey as true.
It is independent of ctrlKey, altKey, and metaKey. Users can hold several at once (for example Shift+Ctrl+click). You can also use event.getModifierState("Shift").
A boolean: true means Shift was pressed during the event; false means it was not.
Did you know?

Shift+click for range selection is so common that users expect it in file lists and data tables. Detecting event.shiftKey is the first step—you still decide which item was the “anchor” of the range in your own app logic.

Next: MouseEvent.webkitForce

Learn non-standard WebKit Force Touch pressure on mouse events.

webkitForce →

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