JavaScript KeyCode Reference
Quick lookup for event.keyCode, event.key, and event.code
Press Any Key
Start typing to see key codes
⌨️
Popular Keycodes
Quick access to the most commonly used keyboard keys
Enter
Escape
Space
Tab
Backspace
Arrow Up
Arrow Down
Arrow Left
Arrow Right
Shift
Control
Alt
Complete Keycode Reference
Browse and search all JavaScript keyboard event codes
JavaScript Keycodes
Click on any code to see more details.
Frequently Asked Questions
Common questions about JavaScript keyboard events and keyCodes
What is keyCode in JavaScript?
keyCode is a deprecated property of keyboard events that returns a numeric code representing the key that was pressed. For example, 13 for Enter, 27 for Escape, and 65 for the letter A. While still supported in browsers, it's recommended to use event.key or event.code instead.
Learn more about keyCode →Why is keyCode deprecated?
keyCode was deprecated because it's hard to read (numeric codes vs. names), inconsistent across browsers, doesn't support international keyboards well, and can't distinguish between left and right modifier keys. The modern event.key and event.code properties solve these problems.
Read the full deprecation guide →What's the difference between keyCode, key, and code?
keyCode (deprecated) returns numeric values like 13 or 65. event.key returns the actual character or key name like 'Enter' or 'a'. event.code returns the physical key location like 'Enter' or 'KeyA', which doesn't change with keyboard layout.
See detailed comparison →How do I detect arrow keys in JavaScript?
Use event.key to detect arrow keys. For example: if (e.key === 'ArrowUp') { }. The arrow key values are 'ArrowUp', 'ArrowDown', 'ArrowLeft', and 'ArrowRight'. Legacy keyCodes are 37-40.
Complete arrow keys guide →Are keyCodes the same across browsers?
For common keys, yes, but there were historical inconsistencies, especially for special keys and international keyboards. This is one reason keyCode was deprecated. The modern event.key and event.code properties are standardized and consistent across all modern browsers.
Check browser compatibility →How do I detect Ctrl, Alt, and Shift keys?
Use the boolean properties e.ctrlKey, e.altKey, e.shiftKey, and e.metaKey to check if modifier keys are pressed during any keyboard event. For example: if (e.ctrlKey && e.key === 's') { } detects Ctrl+S.
Modifier keys guide →Should I use event.key or event.code?
Use event.key for most cases like text input and form handling. Use event.code for game controls or when you need to detect physical key position regardless of keyboard layout (like WASD keys).
When to use each property →How do I prevent arrow keys from scrolling the page?
Call e.preventDefault() in your keydown event handler when arrow keys are detected. For example: if (e.key.startsWith('Arrow')) { e.preventDefault(); }. Only do this when necessary, as users expect arrow keys to scroll.
See examples →