KeyboardEvent

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

KeyboardEvent objects describe a user interaction with the keyboard; each event describes a single interaction between the user and a key (or combination of a key with modifier keys) on the keyboard. The event type (keydown, keypress, or keyup) identifies what kind of keyboard activity occurred.

Note: KeyboardEvent events just indicate what interaction the user had with a key on the keyboard at a low level, providing no contextual meaning to that interaction. When you need to handle text input, use the input event instead. Keyboard events may not be fired if the user is using an alternate means of entering text, such as a handwriting system on a tablet or graphics tablet.

Event UIEvent KeyboardEvent

Constructor

KeyboardEvent()

Creates a new KeyboardEvent object.

Constants

The KeyboardEvent interface defines the following constants.

Keyboard locations

The following constants identify which part of the keyboard the key event originates from. They are accessed as KeyboardEvent.DOM_KEY_LOCATION_STANDARD and so forth.

Keyboard location identifiers
Constant Value Description
DOM_KEY_LOCATION_STANDARD 0x00

The key described by the event is not identified as being located in a particular area of the keyboard; it is not located on the numeric keypad (unless it's the NumLock key), and for keys that are duplicated on the left and right sides of the keyboard, the key is, for whatever reason, not to be associated with that location.

Examples include alphanumeric keys on the standard PC 101 US keyboard, the NumLock key, and the space bar.

DOM_KEY_LOCATION_LEFT 0x01

The key is one which may exist in multiple locations on the keyboard and, in this instance, is on the left side of the keyboard.

Examples include the left Control key, the left Command key on a Macintosh keyboard, or the left Shift key.

DOM_KEY_LOCATION_RIGHT 0x02

The key is one which may exist in multiple positions on the keyboard and, in this case, is located on the right side of the keyboard.

Examples include the right Shift key and the right Alt key (Option on a Mac keyboard).

DOM_KEY_LOCATION_NUMPAD 0x03

The key is located on the numeric keypad, or is a virtual key associated with the numeric keypad if there's more than one place the key could originate from. The NumLock key does not fall into this group and is always encoded with the location DOM_KEY_LOCATION_STANDARD.

Examples include the digits on the numeric keypad, the keypad's Enter key, and the decimal point on the keypad.

Instance properties

This interface also inherits properties of its parents, UIEvent and Event.

KeyboardEvent.altKey Read only

Returns a boolean value that is true if the Alt (Option or ⌥ on macOS) key was active when the key event was generated.

KeyboardEvent.code Read only

Returns a string with the code value of the physical key represented by the event.

Warning: This ignores the user's keyboard layout, so that if the user presses the key at the "Y" position in a QWERTY keyboard layout (near the middle of the row above the home row), this will always return "KeyY", even if the user has a QWERTZ keyboard (which would mean the user expects a "Z" and all the other properties would indicate a "Z") or a Dvorak keyboard layout (where the user would expect an "F"). If you want to display the correct keystrokes to the user, you can use Keyboard.getLayoutMap().

KeyboardEvent.ctrlKey Read only

Returns a boolean value that is true if the Ctrl key was active when the key event was generated.

KeyboardEvent.isComposing Read only

Returns a boolean value that is true if the event is fired between after compositionstart and before compositionend.

KeyboardEvent.key Read only

Returns a string representing the key value of the key represented by the event.

KeyboardEvent.location Read only

Returns a number representing the location of the key on the keyboard or other input device. A list of the constants identifying the locations is shown above in Keyboard locations.

KeyboardEvent.metaKey Read only

Returns a boolean value that is true if the Meta key (on Mac keyboards, the ⌘ Command key; on Windows keyboards, the Windows key (⊞)) was active when the key event was generated.

KeyboardEvent.repeat Read only

Returns a boolean value that is true if the key is being held down such that it is automatically repeating.

KeyboardEvent.shiftKey Read only

Returns a boolean value that is true if the Shift key was active when the key event was generated.

Obsolete properties

KeyboardEvent.charCode Read only

Returns a number representing the Unicode reference number of the key; this property is used only by the keypress event. For keys whose char property contains multiple characters, this is the Unicode value of the first character in that property. In Firefox 26 this returns codes for printable characters.

KeyboardEvent.keyCode Read only

Returns a number representing a system and implementation dependent numerical code identifying the unmodified value of the pressed key.

KeyboardEvent.keyIdentifier Read only

This property is non-standard and has been deprecated in favor of KeyboardEvent.key. It was part of an old version of DOM Level 3 Events.

Instance methods

This interface also inherits methods of its parents, UIEvent and Event.

KeyboardEvent.getModifierState()

Returns a boolean value indicating if a modifier key such as Alt, Shift, Ctrl, or Meta, was pressed when the event was created.

Obsolete methods

KeyboardEvent.initKeyboardEvent()

Initializes a KeyboardEvent object. This is now deprecated. You should instead use the KeyboardEvent() constructor.

Events

The following events are based on the KeyboardEvent type. In the list below, each event links to the documentation for the Element handler for the event, which applies generally to all of the recipients, including Element, Document, and Window.

keydown

A key has been pressed.

keyup

A key has been released.

Obsolete events

keypress

A key that normally produces a character value has been pressed. This event was highly device-dependent and is obsolete. You should not use it.

Usage notes

There are three types of keyboard events: keydown, keypress, and keyup. For most keys, Gecko dispatches a sequence of key events like this:

  1. When the key is first pressed, the keydown event is sent.
  2. If the key is not a modifier key, the keypress event is sent.
  3. When the user releases the key, the keyup event is sent.

Special cases

Some keys toggle the state of an indicator light; these include keys such as Caps Lock, Num Lock, and Scroll Lock. On Windows and Linux, these keys dispatch only the keydown and keyup events.

Note: On Linux, Firefox 12 and earlier also dispatched the keypress event for these keys.

However, a limitation of the macOS event model causes Caps Lock to dispatch only the keydown event. Num Lock was supported on some older laptop models (2007 models and older), but since then, macOS hasn't supported Num Lock even on external keyboards. On older MacBooks with a Num Lock key, that key doesn't generate any key events. Gecko does support the Scroll Lock key if an external keyboard which has an F14 key is connected. In certain older versions of Firefox, this key generated a keypress event; this inconsistent behavior was Firefox bug 602812.

Auto-repeat handling

When a key is pressed and held down, it begins to auto-repeat. This results in a sequence of events similar to the following being dispatched:

  1. keydown
  2. keypress
  3. keydown
  4. keypress
  5. <<repeating until the user releases the key>>
  6. keyup

This is what the DOM Level 3 specification says should happen. There are some caveats, however, as described below.

Auto-repeat on some GTK environments such as Ubuntu 9.4

In some GTK-based environments, auto-repeat dispatches a native key-up event automatically during auto-repeat, and there's no way for Gecko to know the difference between a repeated series of key presses and an auto-repeat. On those platforms, then, an auto-repeat key will generate the following sequence of events:

  1. keydown
  2. keypress
  3. keyup
  4. keydown
  5. keypress
  6. keyup
  7. <<repeating until the user releases the key>>
  8. keyup

In these environments, unfortunately, there's no way for web content to tell the difference between auto-repeating keys and keys that are just being pressed repeatedly.

Example

js
document.addEventListener("keydown", (event) => {
  const keyName = event.key;

  if (keyName === "Control") {
    // do not alert when only Control key is pressed.
    return;
  }

  if (event.ctrlKey) {
    // Even though event.key is not 'Control' (e.g., 'a' is pressed),
    // event.ctrlKey may be true if Ctrl key is pressed at the same time.
    alert(`Combination of ctrlKey + ${keyName}`);
  } else {
    alert(`Key pressed ${keyName}`);
  }
});

document.addEventListener("keyup", (event) => {
  const keyName = event.key;

  // As the user releases the Ctrl key, the key is no longer active,
  // so event.ctrlKey is false.
  if (keyName === "Control") {
    alert("Control key was released");
  }
});

Specifications

Specification
UI Events
# interface-keyboardevent

The KeyboardEvent interface specification went through numerous draft versions, first under DOM Events Level 2 where it was dropped as no consensus arose, then under DOM Events Level 3. This led to the implementation of non-standard initialization methods, the early DOM Events Level 2 version, KeyboardEvent.initKeyEvent() by Gecko browsers and the early DOM Events Level 3 version, KeyboardEvent.initKeyboardEvent() by others. Both have been superseded by the modern usage of a constructor: KeyboardEvent().

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
KeyboardEvent
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
KeyboardEvent() constructor
Chrome – Full support
Chrome 26 (Release date: 2013-03-26)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 31 (Release date: 2014-07-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 26 (Release date: 2013-04-03)
footnote Full support
Firefox for Android – Full support
Firefox for Android 31 (Release date: 2014-07-22)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
altKey
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
charCode
Deprecated
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
code
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 38 (Release date: 2015-05-12)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Partial support
Chrome Android 48 (Release date: 2016-01-26)
footnote Partial support
footnote The value is always empty.
Firefox for Android – Partial support
Firefox for Android 38 (Release date: 2015-05-12)
footnote Partial support
footnote The value is always empty.
Opera Android – Partial support
Opera Android 35 (Release date: 2016-02-04)
footnote Partial support
footnote The value is always empty.
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Partial support
footnote The value is always empty.
WebView Android – Partial support
WebView Android 48 (Release date: 2016-01-26)
footnote Partial support
footnote The value is always empty.
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
ctrlKey
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
getModifierState
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"Accel" as key parameter
Deprecated Non-standard
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 32 (Release date: 2014-09-02)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 32 (Release date: 2014-09-02)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
"Alt" as key parameter
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"AltGraph" as key parameter
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"CapsLock" as key parameter
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"Control" as key parameter
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"Fn" as key parameter
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
"Meta" as key parameter
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"NumLock" as key parameter
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
"OS" as key parameter
Deprecated Non-standard
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – No support
Edge 12 – 18 (Release date: 2015-07-29)
altname
altname Alternate name: Win
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
"ScrollLock" as key parameter
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – No support
Edge 12 – 18 (Release date: 2015-07-29)
altname
altname Alternate name: Scroll
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
"Shift" as key parameter
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
"Symbol" as key parameter
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
initKeyboardEvent
Deprecated
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
isComposing
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 31 (Release date: 2014-07-22)
footnote Full support
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 31 (Release date: 2014-07-22)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
key
Chrome – Full support
Chrome 51 (Release date: 2016-05-25)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's key property is undefined. See bug 41425904.
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 23 (Release date: 2013-08-06)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's key property is undefined. See bug 41425904.
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 51 (Release date: 2016-06-08)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's key property is undefined. See bug 41425904.
Firefox for Android – Full support
Firefox for Android 23 (Release date: 2013-08-06)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's key property is undefined. See bug 41425904.
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's key property is undefined. See bug 41425904.
WebView Android – Full support
WebView Android 51 (Release date: 2016-06-08)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's key property is undefined. See bug 41425904.
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Dead key
Chrome – Full support
Chrome 51 (Release date: 2016-05-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 37 (Release date: 2015-03-31)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 51 (Release date: 2016-06-08)
footnote Full support
Firefox for Android – Full support
Firefox for Android 37 (Release date: 2015-03-31)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 51 (Release date: 2016-06-08)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Non-printable keys
Chrome – Full support
Chrome 51 (Release date: 2016-05-25)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 23 (Release date: 2013-08-06)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 51 (Release date: 2016-06-08)
footnote Full support
Firefox for Android – Full support
Firefox for Android 23 (Release date: 2013-08-06)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 51 (Release date: 2016-06-08)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Printable keys
Chrome – Full support
Chrome 51 (Release date: 2016-05-25)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 29 (Release date: 2014-04-29)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 51 (Release date: 2016-06-08)
footnote Full support
Firefox for Android – Full support
Firefox for Android 29 (Release date: 2014-04-29)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 51 (Release date: 2016-06-08)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
keyCode
Deprecated
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's keyCode property is undefined. See bug 41425904.
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's keyCode property is undefined. See bug 41425904.
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's keyCode property is undefined. See bug 41425904.
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote
footnote When selecting an autocomplete suggestion, a keydown event fires where the event's keyCode property is undefined. See bug 41425904.
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
keyIdentifier
Deprecated Non-standard
Chrome – No support
Chrome 26 – 53 (Release date: 2013-03-26)
footnote Removed in 54 and later
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera 15 – 40 (Release date: 2013-07-02)
footnote Removed in 41 and later
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – No support
Chrome Android 26 – 53 (Release date: 2013-04-03)
footnote Removed in 54 and later
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android 14 – 37 (Release date: 2013-05-21)
footnote Removed in 41 and later
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – No support
Samsung Internet 1.5 – 5.4 (Release date: 2013-09-25)
footnote Removed in 6 and later
WebView Android – No support
WebView Android 4.4 – 53 (Release date: 2013-12-09)
footnote Removed in 54 and later
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
location
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 8 (Release date: 2014-10-16)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 8 (Release date: 2014-09-17)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 8 (Release date: 2014-09-17)
footnote Full support
metaKey
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote
footnote Since Firefox 48, the Windows key is no longer treated as a meta key.
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote
footnote Since Firefox for Android 48, the Windows key is no longer treated as a meta key.
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
repeat
Chrome – Partial support
Chrome 32 – 136 (Release date: 2014-01-14)
footnote Partial support
footnote On Windows and Linux, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Chrome – Full support
Chrome 137 (Release date: 2025-05-27)
footnote
footnote Before Chrome 139, on Linux under X11, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 28 (Release date: 2014-03-18)
footnote Full support
Opera – Partial support
Opera 19 – 120 (Release date: 2014-01-28)
footnote Partial support
footnote On Windows and Linux, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Opera – Full support
Opera 121 (Release date: 2025-08-27)
footnote
footnote Before Opera 123, on Linux under X11, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Partial support
Chrome Android 32 – 136 (Release date: 2014-01-15)
footnote Partial support
footnote On Windows and Linux, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Chrome Android – Full support
Chrome Android 137 (Release date: 2025-05-27)
footnote
footnote Before Chrome Android 139, on Linux under X11, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Firefox for Android – Full support
Firefox for Android 28 (Release date: 2014-03-18)
footnote Full support
Opera Android – Partial support
Opera Android 19 – 89 (Release date: 2014-01-28)
footnote Partial support
footnote On Windows and Linux, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Opera Android – Full support
Opera Android 90 (Release date: 2025-06-18)
footnote
footnote Before Opera Android 91, on Linux under X11, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Partial support
footnote On Windows and Linux, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
WebView Android – Partial support
WebView Android 4.4.3 – 136 (Release date: 2014-06-02)
footnote Partial support
footnote On Windows and Linux, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
WebView Android – Full support
WebView Android 137 (Release date: 2025-05-27)
footnote
footnote Before WebView Android 139, on Linux under X11, if multiple keys are held down, a keydown event for the most recently pressed key will trigger with repeat incorrectly set to false. See bug 40940886.
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
shiftKey
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1.5 (Release date: 2005-11-29)
footnote Full support
Opera – Full support
Opera 12.1 (Release date: 2012-11-20)
footnote Full support
Safari – Full support
Safari 1.2 (Release date: 2004-02-02)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 12.1 (Release date: 2012-10-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
Uses a non-standard name
Has more compatibility info.

Compatibility notes

  • As of Firefox 65, the keypress event is no longer fired for non-printable keys (Firefox bug 968056), except for the Enter key, and the Shift + Enter and Ctrl + Enter key combinations (these were kept for cross-browser compatibility purposes).

See also