Favorites

DOM KeyboardEvent.key Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
KeyboardEvent.key
DOM KeyboardEvent PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The key property of a keyboard event gives the value of the key pressed, such as a, Enter or ArrowUp, taking the keyboard layout and Shift into account.

Description

The read-only key property returns the value of the key pressed. For printable keys it's the character typed, so it reflects the keyboard layout and modifier keys ("a" or "A"). Other keys have names such as "Enter", "Tab", "Escape", "Backspace", "ArrowUp" and " " for the space bar.

Use key for shortcuts that relate to what's printed on the key, and code when the physical position matters, such as WASD controls in games.

When an input method editor (IME) is in use, for example when typing Chinese or Japanese, key may be "Process" and isComposing is true; ignore those events in shortcut handlers. The full list of named key values is defined in the UI Events specification.

Syntax

event.key

Value

A string: the character produced, such as "a" or "A", or a key name such as "Enter", "Escape" or "ArrowLeft".

Example

document.addEventListener('keydown', e => {
  const special = e.key.length > 1 ? '(named key)' : '(character)';
  console.log(JSON.stringify(e.key), special);
});
console.log('Click inside the frame and press keys');

Browser Support

The following information will show you the current browser support for the KeyboardEvent.key property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee