Definition
The accesskey
Attribute allows you to specify a keyboard shortcut to focus or activate a specific element.
Applicable Elements
The accesskey
attribute is a Global Attribute, meaning it can be used with all HTML Elements.
HTML accesskey
Global Attribute
Syntax
<a href="https://www.thewebmaster.com/" accesskey="h">Homepage</a>
Usage
- The
accesskey
attribute must be a single character that a keyboard can generate with a single key-press. It includes accented, and other non-alphabet characters - You can specify multiple accesskeys separated by a space. For example, you could specify s for desktop users, and 0 for mobile users that use a numeric keypad. The browser will automatically choose the appropriate one.
There are a few issues with using access keys:
- An
accesskey
should be used only with careful consideration. It can conflict with the system, or other browser shortcuts, and assistive technologies such as screen readers. - You should ensure any shortcut keys assigned are available on all international keyboard variants.
- You should make sure users are aware of the existence of any
accesskey
assignments, so they are not confused if they inadvertently activate them. - Using a number as an
accesskey
may not be clear for users with cognitive issues.
The activation of the accesskey
attribute depends on your browser, and operating system. See table below:
Windows | Linux | Mac | |
---|---|---|---|
Firefox | Alt + Shift + key | On Firefox 57 or newer: Control + Option + key or Control + Alt + key On Firefox 14 or newer: Control + Alt + key On Firefox 13 or older: Control + key | |
Internet Explorer | Alt + key Alt + Shift + key | N/A | |
Edge | N/A | Control + Option + key Control + Option + Shift + key | |
Google Chrome | Alt + key | ||
Safari | N/A | ||
Opera 15+ | Alt + key | Control + Alt + key | |
Opera 12 | Shift + Esc opens a contents list. You can choose an item from the list by pressing key |
Values
Values can include:
- A single printable character that a keyboard can generate with a single keypress. It must be one Unicode code point in length.
Examples
The following example allows you to activate a hyperlink with an accesskey
. On Windows using Chrome, for example, you would press alt + h. See table above for other browsers \ operating systems.
<a href="https://www.thewebmaster.com/" accesskey="h">Homepage</a>
The following example assigns two access keys; s
and 0
. The user agent will choose the most appropriate depending on the device used.
<form action="/search">
<label>Search: <input type="search" name="name" accesskey="s 0"></label>
<input type="submit">
</form>
Specification
The accesskey
HTML specification for the <accept-charset>
element is as follows:
Browser Support
The accesskey
attribute has the following browser support:
Desktop
Chrome | Edge | Firefox | IE | Opera | Safari | |
---|---|---|---|---|---|---|
accesskey | Yes | Yes | Yes | Yes | Yes | Yes |
Mobile
Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet | |
---|---|---|---|---|---|---|
accesskey | Yes | Yes | Yes | Yes | Yes | Yes |