HTML global attributeGlobal attributes

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
On this page

Example

#
HTML
<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>
Preview

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

#
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 keydown event. You then have full control over the key combination and its description.

Related entries

#

Spotted a mistake or missing an example? Write to us.