Number key codes in JavaScript

Every number key with its event.key, event.code and deprecated keyCode. Top-row digits use keyCode 48–57; numpad digits 96–105 and event.code Numpad0–Numpad9.

Updated

Keyevent.keyevent.codekeyCode
00Digit0 / Numpad048 / 96
11Digit1 / Numpad149 / 97
22Digit2 / Numpad250 / 98
33Digit3 / Numpad351 / 99
44Digit4 / Numpad452 / 100
55Digit5 / Numpad553 / 101
66Digit6 / Numpad654 / 102
77Digit7 / Numpad755 / 103
88Digit8 / Numpad856 / 104
99Digit9 / Numpad957 / 105

Detecting a digit from either row

document.addEventListener('keydown', (e) => {
  if (/^[0-9]$/.test(e.key)) {
    console.log('digit', Number(e.key)); // top row or numpad
  }
});

On French AZERTY keyboards the top row types symbols (&, é, " …) without Shift, so e.key is not a digit there — another reason to test e.key rather than assume positions.

JavaScript Keycode FinderPress any key and instantly see every property of the keyboard event, with a copy-ready keydown snippet for shortcuts.
Open the tool

Frequently asked questions

Is event.key upper or lower case for number?
Letters follow Shift and Caps Lock: event.key is “a” normally and “A” with Shift. event.code stays KeyA either way.
Do key codes change with the keyboard layout?
event.key changes with the layout (on a French AZERTY keyboard the A position types Q); event.code always names the physical key.
Should I still use keyCode?
No — it’s deprecated. Use event.key for characters and event.code for positions.