Shift key code in JavaScript

For Shift, event.key is Shift, event.code is ShiftLeft / ShiftRight and the deprecated keyCode is 16. Press any key in the Key Code Finder to see its values live.

Updated

PropertyValue
event.keyShift
event.codeShiftLeft / ShiftRight
event.keyCode / which (deprecated)16

How to detect Shift

document.addEventListener('keydown', (event) => {
  if (event.key === 'Shift') {
    // Shift was pressed
  }
});

Use event.key to react to what the key means (it follows the keyboard layout) and event.code for its physical position, for example WASD in games. keyCode and which are deprecated: they still work, but their values differ between browsers and layouts.

How browsers treat Shift

Use event.shiftKey to check whether Shift is held during another key or click — don’t track Shift presses yourself. Shift changes event.key (“a” becomes “A”) but not event.code.

In React

<input onKeyDown={(e) => { if (e.key === 'Shift') { /* … */ } }} />
JavaScript Keycode FinderPress any key and instantly see every property of the keyboard event, with a copy-ready keydown snippet for shortcuts.
Open the tool

Frequently asked questions

What is the keyCode for Shift?
16. It’s deprecated, though: use event.key (“Shift”) or event.code (ShiftLeft) in new code.
What is the difference between event.key and event.code?
event.key is the character or action the key produces with the current layout; event.code is the physical key position, the same on every layout.
Should I use keydown or keypress?
keydown. The keypress event is deprecated and doesn’t fire for keys that don’t produce characters, such as Escape or the arrow keys.