---
title: "Function Key Codes: F1–F12 keyCode 112–123, event.key \"F1\""
description: "F1 to F12 send event.key and event.code \"F1\" to \"F12\" and keyCode 112 to 123 (F13 to F24 go to 135). See which ones browsers keep and why laptops need Fn."
url: https://devicetests.com/keycode/function-keys
language: en
---

# Function key codes (F1–F24)

F1 to F12 send event.key and event.code "F1" to "F12" and keyCode 112 to 123; F13 to F24 go on from 124 to 135.

## Every value at a glance

| Key | event.code | event.key | keyCode | event.location |
| - | - | - | - | - |
| F1 | `F1` | `F1` | 112 | 0 (Standard) |
| F2 | `F2` | `F2` | 113 | 0 (Standard) |
| F3 | `F3` | `F3` | 114 | 0 (Standard) |
| F4 | `F4` | `F4` | 115 | 0 (Standard) |
| F5 | `F5` | `F5` | 116 | 0 (Standard) |
| F6 | `F6` | `F6` | 117 | 0 (Standard) |
| F7 | `F7` | `F7` | 118 | 0 (Standard) |
| F8 | `F8` | `F8` | 119 | 0 (Standard) |
| F9 | `F9` | `F9` | 120 | 0 (Standard) |
| F10 | `F10` | `F10` | 121 | 0 (Standard) |
| F11 | `F11` | `F11` | 122 | 0 (Standard) |
| F12 | `F12` | `F12` | 123 | 0 (Standard) |
| F13 | `F13` | `F13` | 124 | 0 (Standard) |
| F14 | `F14` | `F14` | 125 | 0 (Standard) |
| F15 | `F15` | `F15` | 126 | 0 (Standard) |
| F16 | `F16` | `F16` | 127 | 0 (Standard) |
| F17 | `F17` | `F17` | 128 | 0 (Standard) |
| F18 | `F18` | `F18` | 129 | 0 (Standard) |
| F19 | `F19` | `F19` | 130 | 0 (Standard) |
| F20 | `F20` | `F20` | 131 | 0 (Standard) |
| F21 | `F21` | `F21` | 132 | 0 (Standard) |
| F22 | `F22` | `F22` | 133 | 0 (Standard) |
| F23 | `F23` | `F23` | 134 | 0 (Standard) |
| F24 | `F24` | `F24` | 135 | 0 (Standard) |

keyCode as Chrome and Edge send it on Windows. The Mac column (Chrome and Safari on a Mac) and the Firefox column show only numbers that differ; some keys also differ by system, as the text below says. event.which is always the same number as keyCode. event.key is for a US layout without Shift.

## Code to react to F1

Recommended: match event.key

```
document.addEventListener('keydown', (event) => {
  if (event.key === 'F1') {
    // Your code here
  }
});
```

Match the key's place: event.code

```
document.addEventListener('keydown', (event) => {
  if (event.code === 'F1') {
    // Your code here
  }
});
```

Old code that still uses keyCode (deprecated)

```
document.addEventListener('keydown', (event) => {
  if (event.keyCode === 112) {
    // Your code here
  }
});
```

## Which value to use

Check `event.key === 'F2'` (or whichever number you need). For function keys, `event.key` and `event.code` are the same text, “F1” to “F24”, on every keyboard layout, so either one works.

`keyCode` runs from 112 for F1 to 123 for F12, then on to 135 for F24. It still arrives, but it is deprecated, and older Mac browsers sent 0 for F21 to F24 (see below).

Plan for users who can’t press a function key easily. Laptops and Mac keyboards put brightness, volume and media controls on the same keys, and many compact keyboards have no F row at all. Give every F-key shortcut a second way in, such as a button or a letter shortcut.

## What trips people up

### F5 reloads the page and F12 opens the developer tools

The browser has its own job for most function keys. In Chrome on Windows: F1 opens the help, F3 finds, F5 reloads, F6 jumps to the address bar, F7 turns on caret browsing, F10 moves focus to the toolbar, F11 goes fullscreen and F12 opens the developer tools. Calling `event.preventDefault()` in keydown stops many of these, such as F5, but not all of them. Once the browser is fullscreen, the F11 that leaves it never reaches the page. Don’t build anything important on F5, F11 or F12.

### Pressing F5 changes the volume instead

On many laptops the top row does media jobs first, and F1 to F12 need the Fn key. Then the browser gets a media key such as `AudioVolumeUp` (keyCode 175), or nothing at all for brightness keys. Many laptops have an Fn lock, often Fn + Esc, or a setting that swaps this. Your page can’t change it, so tell users to hold Fn.

### On a Mac, the F keys change the screen and the sound

Mac keyboards send brightness, volume and other controls from the top row unless the user holds fn or turns on “Use F1, F2, etc. keys as standard function keys” in the keyboard settings. Even then, macOS keeps some for itself: F11 can show the desktop. Mac users also expect Cmd shortcuts, such as Cmd + R to reload, more than F keys.

### Alt+F4 and Ctrl+F4 never reach the page

On Windows, Alt + F4 closes the window and Ctrl + F4 closes the tab in Chrome and Edge. They are gone before your handler runs. Don’t use them as shortcuts.

### F21 to F24 don’t work on a Mac

macOS has no keys above F20, and older Chrome and Safari versions sent keyCode 0 for F21 to F24. Don’t rely on those keys on a Mac. Keys above F12 exist only on some keyboards: full-size Apple keyboards go up to F19, and macro pads and gaming keyboards often send F13 to F24 because no other app uses them.

## Related keys

- [Print Screen key code](https://devicetests.com/keycode/print-screen)
- [Escape key code](https://devicetests.com/keycode/escape)
- [Alt key code](https://devicetests.com/keycode/alt)
- [Control key code](https://devicetests.com/keycode/control)
- [Keycode finder: press any key to see its codes](https://devicetests.com/keycode)
- [All key codes in one table](https://devicetests.com/keycode#key-codes)
