In JavaScript, the keypress event fires when a letter, number, punctuation, or symbol key is pressed, or when Enter is pressed — including Enter with Shift or Ctrl (MDN). Modifier keys alone (Alt, Shift, Ctrl, Meta, Esc) usually do not fire it.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Swap the event name. Use keydown instead of keypress.
Keep event.key. Meaning stays clear ("Enter", "Escape").
Gain Escape (and more). Control keys work reliably.
Follow MDN. Prefer keydown or beforeinput in new code.
Compatibility
Browser Support
Element keypress is still widely implemented for compatibility, but MDN marks it Deprecated. Do not add it to new code — migrate to keydown or beforeinput.
✓ Deprecated
Element keypress
Legacy character-key KeyboardEvent — still present, not recommended.
—Deprecated
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
keypressDeprecated
Bottom line: Still works in many browsers for old pages, but MDN warns against new use. Prefer keydown for keys and beforeinput for text edits.
Frequently Asked Questions
It fires when a letter, number, punctuation, or symbol key is pressed, or when Enter is pressed (including with Shift or Ctrl). Modifier keys alone (Alt, Shift, Ctrl, Meta, Esc) usually do not fire keypress (MDN).
MDN marks Element keypress as Deprecated only — not Experimental and not Non-standard. Avoid it in new projects; prefer keydown or beforeinput.
MDN: use beforeinput or keydown. Prefer keydown for shortcuts and all-key detection; use beforeinput when you need to inspect text edits before they apply.
A KeyboardEvent (inherits from UIEvent and Event), same family as keydown and keyup.
keypress historically targeted character-producing keys. Many control and modifier keys do not fire it — another reason modern code prefers keydown.