76 of 133 menu

The accesskey attribute

The accesskey attribute allows you to access an element using a key combination. The attribute value must be a lowercase Latin letter or number.

Different browsers use different keyboard shortcuts. For example, in Firefox it would be Shift + Alt + attribute value accesskey, and in Safari, Chrome and IE: Alt + attribute value accesskey.

When using the keyboard shortcut for the HTML form text fields (input and textarea), they will get focus, for checkboxes and radio the state will change from checked to unchecked and vice versa, for the a tag the link will be followed.

The attribute applies to tags: a, area button, input, label, legend, textarea.

Example

Let's assign the checkbox a hotkey of z. Press Shift + Alt + z in Firefox or Alt + z in other browsers to toggle the state of this checkbox:

<input type="checkbox" accesskey="z">

:

Example

And here we'll assign the hotkey w to the input text input field. Press Shift + Alt + w in Firefox or Alt + w in other browsers to give this tag input focus:

<input type="text" accesskey="w">

:

Example

Let's assign hotkeys s and q to two radio switches:

<input type="radio" name="radio" accesskey="s"> <input type="radio" name="radio" accesskey="q">

:

See also

  • attribute autocomplete,
    which sets autofill for form fields
  • attribute tabindex,
    which allows you to change focus by pressing Tab
byenru