Table of Contents

HTML - Accesskey Attribute (keyboard shortcut)

About

All HTML elements may have the accesskey content attribute set.

The accesskey attribute's value 1) is used by the user agent as a guide for creating a keyboard shortcut that focuses (ie activates) the element.

Syntax

The value must be:

Example

accesskey="s 0"
accesskey="A"

Assigned access key by Browsers

Advanced

If you want to create advanced keyboard shortcut, you can also use the keydown event (or related wrapping library)

Example:

<form id="search-form">
     <span id="search-input-container">
          <input type="search" id="search-input" placeholder="Search ..." aria-label="Search for...">
     </span>
</form>
var searchInput = document.getElementById('search-input');
// window.parent because this code run in a iframe, otherwise just document
window.parent.addEventListener('keydown', function(event) {
        event.ctrlKey && event.key === '\\' && (event.preventDefault(),searchInput.focus())
})