HTML Accesskey Attribute

The HTML accesskey attribute specifies a keyboard shortcut that users can use to activate or focus an HTML element. It can make certain website actions quicker to access without requiring users to navigate through every element on a page.

For example, you can assign a keyboard shortcut to a link, button, or form control. However, the exact key combination depends on the browser, operating system, and other keyboard shortcuts.

In this tutorial, you will learn how the HTML accesskey attribute works, how to use it with different elements, and what to consider when implementing keyboard shortcuts.

What Is the HTML Accesskey Attribute?

The accesskey attribute assigns a keyboard shortcut to an HTML element.

Here is a simple example:

<button accesskey="s" type="button">
    Save
</button>

This button has the access key s. Depending on the browser and operating system, users may be able to activate or focus on the button by pressing s together with a modifier key.

The accesskey attribute is a global HTML attribute, so it can be used with many HTML elements. You can learn more about these attributes in our HTML global attributes tutorial.

HTML Accesskey Attribute Syntax

The basic syntax is:

<tagname accesskey="key">Content</tagname>

Replace key with the character you want to assign as the shortcut.

For example:

<a href="https://web4learners.com/" accesskey="h">
    Home
</a>

<button type="button" accesskey="c">
    Continue
</button>

The link and button have different access keys. The browser determines how users invoke those shortcuts.

Using Accesskey with Links

You can assign an access key to a link to help users navigate to another page.

<a href="https://web4learners.com/" accesskey="h">
    Visit Web4Learners
</a>

The access key is h. Depending on the browser and operating system, users can press the appropriate modifier combination to focus on or activate the link.

Remember that access keys do not replace ordinary navigation. The link should remain usable through mouse clicks, keyboard Tab navigation, and assistive technologies.

Using Accesskey with Form Controls

The accesskey attribute can also be used with form elements.

<form>
    <label for="username">Username:</label>
    <input
        type="text"
        id="username"
        accesskey="u">

    <button type="submit" accesskey="s">
        Submit
    </button>
</form>

In this example, u is assigned to the username field, while s is assigned to the submit button.

Depending on the browser and operating system, invoking an access key may move focus to a field or activate a control.

For more examples of form controls, see our HTML input tutorial.

How to Use an Access Key

The HTML attribute specifies the shortcut character, but it does not define one universal keyboard combination.

For example, the access key s might be invoked using a combination such as:

  • Alt + S in some browser and operating system configurations.
  • Alt + Shift + S in certain other configurations.
  • Another browser-specific modifier combination on different systems.

These combinations are examples, not universal rules. Check the relevant browser’s documentation before publishing shortcut instructions.

Best Practices for the Accesskey Attribute

Follow these recommendations when using access keys:

  • Choose shortcut characters that are easy to remember.
  • Avoid shortcuts that conflict with common browser or operating system commands.
  • Do not assign the same shortcut to several important actions.
  • Clearly explain available shortcuts to users.
  • Test shortcuts across your target browsers and operating systems.
  • Ensure all controls remain accessible through standard keyboard navigation.

Access keys can create conflicts with browser features, assistive technologies, or keyboard layouts. For many websites, clear labels and standard keyboard navigation are more useful than custom shortcuts.

Difference Between Accesskey and Tabindex

Both attributes affect keyboard interaction, but they have different purposes.

FeatureAccesskeyTabindex
Main purposeAssigns a keyboard shortcutControls focusability and sequential focus order
Exampleaccesskey="s"tabindex="0"
How it worksUses a browser-dependent key combinationWorks with keyboard focus and the Tab sequence
Common useQuick access to a particular actionMaking elements focusable or managing focus

Read our HTML tabindex attribute tutorial to learn more about keyboard focus and navigation.

Frequently Asked Questions

Is the HTML accesskey attribute supported by modern browsers?

Yes, it is supported by modern browsers, but the keyboard combinations used to invoke access keys vary by browser and operating system.

Can I use accesskey on a button?

Yes. You can assign an access key to a button or many other HTML elements.

Does accesskey always use the Alt key?

No. The modifier keys depend on the browser and operating system. Some environments use different combinations.

Can two elements have the same access key?

You can assign the same character to multiple elements, but doing so can create conflicts or unpredictable behavior. It is better to choose distinct shortcuts for important actions.

Is accesskey required in HTML?

No. It is an optional attribute. Most websites can provide good keyboard accessibility through native HTML controls and logical Tab navigation without defining custom access keys.