JavaScript MouseEvent shiftKey Property

Beginner
5 min read
Updated: Nov 2026
5 examples
Property

Definition

MouseEvent.shiftKey is a read-only boolean: true if the Shift key was pressed when the mouse event happened, otherwise false (MDN).

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

Syntax

Use event.shiftKey. Start with this line.

JavaScript
event.shiftKey
CallWhat it does
event.shiftKeyPrimary signature.

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

Library declarations
JavaScript
event.shiftKey

Parameters

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

Return Value

Return ValueDescription
*true if Shift was held, else false

JavaScript Examples

Example 1 — Log on click (MDN)

Show whether the Shift key is pressed on each click.

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

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

How It Works

  1. Listen for click. MDN’s basic demo event.
  2. Read e.shiftKey. Boolean for Shift at that moment.
  3. Update the log. Instant feedback for students.
  4. Hold Shift and click again. The value flips to true.

Example 2 — Shift+Click Branch

Use Shift+click for “extend selection” style behavior.

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

How It Works

  1. Branch on shiftKey. Two clear code paths.
  2. Normal click. Select a single item.
  3. Shift+click. Extend / range-select (common desktop UX).
  4. Keep handlers short. Decision is one boolean check.

Example 3 — Synthetic MouseEvent

Set shiftKey when creating an event in code.

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

  1. Pass shiftKey: true. Constructor option sets the flag.
  2. Read-only afterward. Matches what you configured.
  3. Useful for tests. No need to hold a real key.
  4. Default is false. Omit it when Shift is not needed.

Example 4 — All Modifier Flags

Log shiftKey next to Ctrl, Alt, and Meta on each click.

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

How It Works

  1. Four sibling properties. Same event, different keys.
  2. Hold combinations. e.g. Shift+Ctrl → both true.
  3. Independent flags. Shift does not imply Control.
  4. Great for debugging. See exactly which modifiers fired.

Example 5 — getModifierState("Shift")

Compare the boolean property with the modifier-state API.

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

  1. shiftKey is the shortcut. Direct boolean on the event.
  2. getModifierState("Shift"). Same idea via a string name.
  3. They match here. Useful when you already use getModifierState for other keys.
  4. Prefer shiftKey for clarity when you only care about Shift.

Browser Support

MouseEvent.shiftKey is Baseline Widely available (MDN, since July 2015). Safe for Shift+mouse UIs everywhere.

✓ Baseline · Widely available

MouseEvent.shiftKey

Supported across Chrome, Firefox, Safari, Edge, Opera, and legacy IE. Read-only boolean for the Shift key.

99% Browser support
Google Chrome shiftKey · full support
Full support
Microsoft Edge shiftKey · Chromium
Full support
Apple Safari shiftKey · full support
Full support
Mozilla Firefox shiftKey · full support
Full support
Opera shiftKey · full support
Full support
Internet Explorer shiftKey · legacy
Legacy support
MouseEvent.shiftKey Excellent

Bottom line: Use freely for Shift+click and range-select patterns. Pair with other modifier flags when needed.

Frequently Asked Questions

A read-only boolean that is true when the Shift key was held during that mouse event, and false otherwise (MDN).
No. MDN marks MouseEvent.shiftKey as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Range selection in lists and file trees, alternate toolbar actions, and “extend selection” UX. Branch with if (event.shiftKey) { … }.
Pass shiftKey: true in the options object: 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 (MDN).

Next: webkitForce

Learn how event.webkitForce reports Force Touch pressure in WebKit.

webkitForce 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.

10 people found this page helpful