We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

This page is not complete.

The KeyboardEvent.key read-only property returns the value of a key or keys pressed by the user. Its value is determined as follows:

See a full list of key values.

  • If the pressed key has a printed representation, the returned value is a non-empty Unicode character string containing the printable representation of the key.
  • If the pressed key is a control or special character, the returned value is one of the pre-defined key values.
  • If the KeyboardEvent represents the press of a dead key, the key value must be "Dead".
  • If more than one key is pressed and the combination includes a modifier that makes the resulting keystroke non printing, the returned value is the printable character. For example, if the combination were Control + a, the letter "a" is returned.
  • Some specialty keyboard keys (such as the extended keys for controlling media on multimedia keyboards) don't generate key codes on Windows; instead, they trigger WM_APPCOMMAND events. These events get mapped to DOM keyboard events, and are listed among the "Virtual key codes" for Windows, even though they aren't actually key codes.
  • If the key cannot be identified, the returned value is "Unidentified".

This page is undergoing heavy updating to improve its layout, modernize its content, and bring everything up to date. Newer content is nearer the top; to find the older tables, see Previous versions of tables. Once the updates are finished, that content will be removed. No information should be lost once it's all done.


This example uses EventTarget.addEventListener() to listen for keydown events. When they occur,  the key's value is checked to see if it's one of the keys the code is interested in, and if it is, it gets processed in some way (possibly by steering a spacecraft, perhaps by changing the selected cell in a spreadsheet).

window.addEventListener("keydown", function (event) {
  if (event.defaultPrevented) {
    return; // Do nothing if the event was already processed

  switch (event.key) {
    case "ArrowDown":
      // Do something for "down arrow" key press.
    case "ArrowUp":
      // Do something for "up arrow" key press.
    case "ArrowLeft":
      // Do something for "left arrow" key press.
    case "ArrowRight":
      // Do something for "right arrow" key press.
    case "Enter":
      // Do something for "enter" or "return" key press.
    case "Escape":
      // Do something for "esc" key press.
      return; // Quit when this doesn't handle the key event.

  // Cancel the default action to avoid it being handled twice
}, true);


Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
The definition of 'KeyboardEvent.key' in that specification.
Obsolete Initial definition, included key values.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support


(Yes) 23.0 (23.0) 9.0[1] 38.0 (Yes)
non-printable keys 51.0 ? 23.0 (23.0) 9.0[1] 38.0 ?
printable keys 51.0 ? 29.0 (29.0) 9.0[1] 38.0 ?
dead key 51.0 ? No support No support 38.0 ?
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support 51.0 (Yes) 23.0 (23.0) ? 38.0 (Yes) 51.0
non-printable keys of virtual keyboard No support 51.0 ? 23.0 (23.0) ? 38.0 ? 51.0
printable keys of virtual keyboard No support 51.0 ? ? ? 38.0 ? 51.0
non-printable keys of physical keyboard No support 51.0 ? 23.0 (23.0) ? 38.0 ? 51.0
printable keys of physical keyboard No support 51.0 ? 29.0 (29.0) ? 38.0 ? 51.0

[1]: Internet Explorer's implementation does not completely match the current spec because it is based on an older version of the spec.

Document Tags and Contributors

 Last updated by: Jode,