HTML accesskey Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Accessibility

What You’ll Learn

The accesskey attribute provides a way to define keyboard shortcuts for accessing specific elements on a web page. By assigning a key to an element, users can quickly navigate to it, improving accessibility and user experience.

01

Keyboard Shortcuts

Focus elements quickly.

02

Global Attribute

Works on many elements.

03

Single Character

One letter or number.

04

Modifier Keys

Alt or Ctrl+Option.

05

accessKey

JavaScript DOM property.

06

Use Sparingly

Avoid shortcut conflicts.

Purpose of accesskey

The primary purpose of the accesskey attribute is to enhance the accessibility of a web page by allowing users to navigate to important elements using keyboard shortcuts. This is particularly beneficial for users with mobility issues who may find it challenging to use a mouse for navigation.

💡
Browser Modifier Required

Users do not press the accesskey alone. They combine it with a browser-specific modifier—typically Alt on Windows/Linux or Ctrl + Option on macOS.

📝 Syntax

Add accesskey to any focusable or activatable element with a single character value:

accesskey.html
<button accesskey="h">Home</button>

Syntax Rules

  • Value is a single character (letter, digit, or symbol where supported).
  • Case usually does not matter—browsers treat keys case-insensitively.
  • In JavaScript, use the camelCase property accessKey.
  • Do not assign the same accesskey to multiple visible elements on one page.

💎 Values

The accesskey attribute accepts single-character values, typically a letter or a number. These values are used as the access key that, when combined with a browser-specific modifier key, triggers the associated element:

  • accesskey="h" — Letter keys for navigation (Home, Help, etc.).
  • accesskey="1" — Number keys for ordered shortcuts.
  • accesskey="s" — Mnemonic keys matching the first letter of an action (Save, Search).
common-values.html
<button accesskey="h">Home</button>
<a href="/search" accesskey="s">Search</a>
<input type="submit" value="Go" accesskey="g">

⚡ Quick Reference

PlatformModifier + accesskeyExample
Windows / LinuxAlt + keyAlt + H
macOSCtrl + Option + keyCtrl + Option + H
HTML attributeaccesskey="h"On button or link
JavaScriptel.accessKey = "p"camelCase property
Value typeSingle characterLetter or digit
Attribute typeGlobalMost HTML elements

Applicable Elements

accesskey is a global attribute and can be used on most HTML elements, especially those that receive focus or can be activated:

ElementCommon useNotes
<button>Action shortcutsFocuses and may activate
<a>Navigation linksFollows the link on activation
<input>Form controlsFocuses the field
<label>Associated control focusActivates linked input

Examples Gallery

Navigation buttons, dynamic JavaScript shortcuts, and link access keys.

👀 Live Preview

Three buttons with letter access keys (try Alt + H, A, or C on Windows):

Example — Navigation Buttons

Let’s explore a simple example of how to use the accesskey attribute in an HTML document:

accesskey.html
<button accesskey="h">Home</button>
<button accesskey="a">About</button>
<button accesskey="c">Contact</button>
Try It Yourself

How It Works

In this example, each button is assigned a different access key: h for Home, a for About, and c for Contact. Users activate these buttons by pressing the designated access key with the browser modifier.

Dynamic Values with JavaScript

You can dynamically set the accesskey attribute using JavaScript based on user preferences or dynamic content changes:

dynamic-accesskey.html
<script>
  document.getElementById("dynamicElement").accessKey = "p";
</script>
Try It Yourself

How It Works

In this script, the accesskey attribute is dynamically set to p for an element with the id dynamicElement. Note the camelCase accessKey property in JavaScript.

♿ Accessibility

  • Document shortcuts — List assigned access keys in help text or visible labels so users can discover them.
  • Avoid conflicts — Do not use keys that clash with browser, OS, or screen reader shortcuts.
  • Prefer semantic HTML — Use skip links, logical tab order, and native focus before relying on accesskey.
  • Test across browsers — Modifier key behavior varies; verify on Windows, macOS, and Linux.
  • Unique keys per page — Duplicate accesskey values cause unpredictable focus behavior.

🧠 How accesskey Works

1

Author assigns accesskey

Set a single character on a button, link, or input.

Markup
2

User presses modifier + key

Browser interprets the shortcut using platform conventions.

Keyboard
3

Element receives focus

The target element is focused or activated, depending on its type.

Action
=

Faster keyboard navigation

Power users and assistive-tech users reach key controls without a mouse.

Browser Support

The accesskey attribute is supported in all modern browsers. Modifier key combinations and focus behavior may differ slightly by platform.

HTML5 · Fully supported

Universal shortcut attribute

All major browsers honor accesskey on supported elements.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 9+ supported
Full support
Opera Fully supported
Full support
accesskey attribute 99% supported

Bottom line: Use accesskey when shortcuts add clear value; test modifier behavior on each target platform.

💡 Best Practices

✅ Do

  • Assign keys that are intuitive and easy to remember
  • Document access keys in visible help text or tooltips
  • Test shortcuts across browsers and operating systems
  • Use unique accesskey values on each page
  • Combine with skip links and logical tab order

❌ Don’t

  • Use keys that conflict with browser or system shortcuts
  • Assign accesskey to every control on the page
  • Assume users will discover shortcuts without documentation
  • Duplicate the same accesskey on multiple elements
  • Rely on accesskey as your only accessibility strategy

Conclusion

The accesskey attribute is a powerful tool for improving the accessibility and usability of web pages. By incorporating keyboard shortcuts thoughtfully, you can make navigation more efficient for users, particularly those with disabilities or those who prefer using the keyboard over the mouse.

Use access keys sparingly, document them clearly, and always test behavior across browsers to ensure a consistent experience.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about accesskey

Bookmark these before adding keyboard shortcuts to your UI.

5
Core concepts
🌐 02

Global Attribute

Many elements.

Scope
📝 03

Single Character

One letter/digit.

Values
⚙️ 04

accessKey

JavaScript property.

Dynamic
05

Use Sparingly

Avoid conflicts.

A11y

❓ Frequently Asked Questions

It assigns a keyboard shortcut to an element. Users press a modifier key plus the accesskey character to focus or activate it.
It is a global attribute on buttons, links, inputs, labels, and most other HTML elements.
Windows/Linux: Alt + key. macOS: Ctrl + Option + key.
Use element.accessKey = "p" (camelCase, no hyphen).
No. Use it sparingly for high-value shortcuts. Avoid conflicts with browser and assistive technology keys.
Yes in all modern browsers. Modifier key behavior may vary slightly by platform.

Add keyboard shortcuts responsibly

Practice the accesskey attribute with buttons, links, and dynamic JavaScript in the Try It editor.

Try navigation buttons →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful