accesskey
A keyboard shortcut that moves focus to an element or activates it right away.
- Applies to
- All HTML elements, but it makes sense on links, buttons and form fields
Example
#<style>
p { margin: 0 0 12px; }
kbd { padding: 1px 6px; border: 1px solid #555; border-radius: 4px; font-size: 12px; }
</style>
<p><label>Name <input type="text" name="name" accesskey="n"></label> <kbd>N</kbd></p>
<p><label>Email <input type="email" name="email" accesskey="m"></label> <kbd>M</kbd></p>
<button type="button" accesskey="s" onclick="this.textContent = 'Request sent'">
Send <kbd>S</kbd>
</button>Click the preview, then press Alt + N (Chrome and Edge on Windows), Alt + Shift + N (Firefox) or Control + Option + N (Mac). Focus moves to the βNameβ field. The shortcut with the letter S clicks the button right away.
Definition and usage
#The accesskey attribute assigns an element an access key, that is, a keyboard shortcut. The value is a single character, most often a letter or a digit. When the shortcut is pressed, the browser focuses the element, and buttons and links are usually activated right away, as if someone had clicked them.
The character itself is only part of the shortcut. The browser adds the rest: in Chrome and Edge on Windows you press Alt plus the character, in Firefox Alt, Shift and the character, and on a Mac Control, Option and the character. The page has no influence over this, so if you describe shortcuts on screen, take the different browsers into account.
Access keys are rarely used today. They can clash with browser, system and screen reader shortcuts, and users usually do not know they exist, because the browser does not show them anywhere. They work best in applications that someone uses every day, for example an order-handling panel, and only if the shortcuts are documented.
Syntax
#<element accesskey="character">β¦</element>How to press an access key
#Chrome and Edge on Windows
Alt + character
The shortest combination, but it easily clashes with browser shortcuts, for example Alt + D, which jumps to the address bar.Firefox on Windows and Linux
Alt + Shift + character
The extra Shift reduces the risk of a clash with browser menu shortcuts.Safari, Chrome and Firefox on Mac
Control + Option + character
The same combination in all popular browsers on macOS.
Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- If you add access keys, show them on screen, for example with an underlined letter in the label or a list of shortcuts. A shortcut nobody knows about helps no one.
- Do not use characters the browsers already take, such as D and F, and do not assign the same character to two elements.
- In web applications, shortcuts are often better handled in a script through the
keydownevent. You then have full control over the key combination and its description.
Related entries
#- tabindexDecides whether an element can be focused with the Tab key and in what order.
- onkeydownRuns JavaScript code the moment a key is pressed. Used for keyboard shortcuts and for handling keys such as Enter or Escape.
- <kbd>Input entered by the user: keys, keyboard shortcuts, and commands to type.
- <button>A clickable button: submits a form, clears it, or runs an action on the page.
- autofocusSets focus on an element right after the page loads or after a dialog opens.
Spotted a mistake or missing an example? Write to us.