In JavaScript, the keydown event fires when a key is pressed (MDN). Unlike the Deprecatedkeypress event, it fires for all keys — whether or not they produce a character.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Check isComposing. True while an IME session is active.
Also check 229. MDN: legacy marker for IME-processed keys.
Return early. Avoid treating composition keys as shortcuts.
Why it matters. Improves compatibility for CJKT text input.
Compatibility
Browser Support
Element keydown is Baseline Widely available (MDN: since July 2015). Safe for shortcuts and keyboard UX in modern and older evergreen browsers.
✓ Baseline · Widely available
Element keydown
KeyboardEvent when a key is pressed — long-established across browsers.
99%Widely available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
keydownBaseline
Bottom line: Prefer keydown/keyup over keypress. Use key for meaning, code for physical shortcuts, and filter IME composition when needed.
Frequently Asked Questions
It fires when a key is pressed. Unlike the deprecated keypress event, keydown fires for all keys — whether or not they produce a character (MDN).
No. MDN marks Element keydown as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. (keypress is the deprecated relative.)
A KeyboardEvent. Useful properties include key, code, altKey, ctrlKey, shiftKey, metaKey, repeat, and isComposing.
key is the produced value (for example "a" or "Enter"), considering layout and Shift. code is the physical key position (for example "KeyA"), which stays stable across layouts.
keydown fires when the key goes down (and may repeat while held). keyup fires when the key is released.
MDN: skip when event.isComposing is true, and also when event.keyCode === 229 (legacy IME marker), for better CJKT compatibility.