Keyboard eventsBaseline · Widely available
The keydown and keyup events fire for each key press (or, with modifier keys, a combination of key presses) on a keyboard.
Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.
Browser support
DesktopChrome
1+Supportedsince Dec 11, 2008
Current: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157Safari
1–1.1Not supported
1.2+Supportedsince Feb 2, 2004
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157Safari iOS
1+Supportedsince Jun 29, 2007
Current: 27How to use
This feature is Baseline widely available — use it freely, no fallback needed.
Example
Full syntax and examples are on MDN: keydown event.
Feature detection
JS · check before using
if ("KeyboardEvent" in globalThis) {
// KeyboardEvent is available
} else {
// load a polyfill or use a fallback
}Sub-features
Support for each part of the feature (27). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Element.keydown_event | 1 | 12 | 6 | 1.2 | 18 | 6 | 1 |
| Element.keyup_event | 1 | 12 | 6 | 1.2 | 18 | 6 | 1 |
| KeyboardEvent | 1 | 12 | 1.5 | 1.2 | 18 | 4 | 1 |
| KeyboardEvent.KeyboardEvent | 26 | 12 | 31 | 7 | 26 | 31 | 7 |
| KeyboardEvent.altKey | 1 | 12 | 1.5 | 1.2 | 18 | 4 | 1 |
| KeyboardEvent.code | 48 | 79 | 38 | 10.1 | ✕ | ✕ | 10.3 |
| KeyboardEvent.ctrlKey | 1 | 12 | 1.5 | 1.2 | 18 | 4 | 1 |
| KeyboardEvent.getModifierState | 30 | 12 | 15 | 10.1 | 30 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_alt | 30 | 12 | 15 | 10.1 | 30 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_altgraph | 48 | 79 | 15 | 10.1 | 48 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_capslock | 48 | 12 | 15 | 10.1 | 48 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_control | 30 | 12 | 15 | 10.1 | 30 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_fn | 48 | 79 | 15 | ✕ | 48 | 15 | ✕ |
| KeyboardEvent.getModifierState.key_parameter_meta | 30 | 79 | 15 | 10.1 | 30 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_numlock | 48 | 79 | 15 | ✕ | 48 | 15 | ✕ |
| KeyboardEvent.getModifierState.key_parameter_scrolllock | 48 | 79 | 15 | ✕ | 48 | 15 | ✕ |
| KeyboardEvent.getModifierState.key_parameter_shift | 30 | 12 | 15 | 10.1 | 30 | 15 | 10.3 |
| KeyboardEvent.getModifierState.key_parameter_symbol | 48 | 79 | ✕ | ✕ | 48 | ✕ | ✕ |
| KeyboardEvent.isComposing | 56 | 79 | 31 | ✕ | 56 | 31 | ✕ |
| KeyboardEvent.key | 51 | 12 | 23 | 10.1 | 51 | 23 | 10.3 |
Show 7 more
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| KeyboardEvent.key.dead_key | 51 | 79 | 37 | 10.1 | 51 | 37 | 10.3 |
| KeyboardEvent.key.non_printable_keys | 51 | 12 | 23 | 10.1 | 51 | 23 | 10.3 |
| KeyboardEvent.key.printable_key | 51 | 12 | 29 | 10.1 | 51 | 29 | 10.3 |
| KeyboardEvent.location | 30 | 12 | 15 | 8 | 30 | 15 | 8 |
| KeyboardEvent.metaKey | 1 | 12 | 1.5 | 1.2 | 18 | 4 | 1 |
| KeyboardEvent.repeat | 137 | 12 | 28 | 10.1 | 137 | 28 | 10.3 |
| KeyboardEvent.shiftKey | 1 | 12 | 1.5 | 1.2 | 18 | 4 | 1 |