Skip to content

The accesskey Attribute

Global Attribute

The accesskey attribute specifies a keyboard shortcut to activate or focus an element. While it provides quick keyboard access to elements, it should be used cautiously due to potential conflicts with browser and assistive technology shortcuts.

<element accesskey="character">Content</element>
ValueDescription
Single characterAny single character (letter, number, or symbol)
Multiple charactersSpace-separated list for alternative shortcuts

The actual key combination varies by browser and operating system:

Browser/OSActivation
Chrome (Windows/Linux)Alt + accesskey
Chrome (Mac)Ctrl + Option + accesskey
Firefox (Windows/Linux)Alt + Shift + accesskey
Firefox (Mac)Ctrl + Option + accesskey
Safari (Mac)Ctrl + Option + accesskey
Edge (Windows)Alt + accesskey
Result
Result
Result
Result

Be aware of reserved shortcuts:

<!-- AVOID: Conflicts with browser shortcuts -->
<button accesskey="f">Find</button> <!-- Ctrl+F = Browser find -->
<button accesskey="t">New Tab</button> <!-- Ctrl+T = New tab -->
<button accesskey="w">Close</button> <!-- Ctrl+W = Close tab -->
<button accesskey="r">Refresh</button> <!-- Ctrl+R = Reload -->
<!-- BETTER: Use less common keys -->
<button accesskey="1">Home</button>
<button accesskey="2">Search</button>
<button accesskey="s">Save</button>

Show users which keys are available:

<style>
/* Underline the access key character */
button u {
text-decoration: underline;
text-decoration-color: #3b82f6;
text-decoration-thickness: 2px;
}
</style>
<button accesskey="s"><u>S</u>ave</button>

Always inform users about available shortcuts:

<div class="keyboard-shortcuts-help">
<h3>Keyboard Shortcuts</h3>
<ul>
<li><kbd>Alt+S</kbd> - Save document</li>
<li><kbd>Alt+H</kbd> - Go to home</li>
<li><kbd>Alt+?</kbd> - Show help</li>
</ul>
</div>

Access keys may not work well for all languages:

<!-- English: "Save" = S -->
<button accesskey="s"><u>S</u>ave</button>
<!-- German: "Speichern" = S -->
<button accesskey="s"><u>S</u>peichern</button>
<!-- French: "Enregistrer" = E -->
<button accesskey="e"><u>E</u>nregistrer</button>

Only assign access keys to frequently used elements:

<!-- Good: Essential actions -->
<button accesskey="s">Save</button>
<button accesskey="Enter">Submit</button>
<input type="search" accesskey="/">
<!-- Avoid: Every single element -->
<!-- Don't make every button/link have an accesskey -->

Access keys work with screen readers, but can cause issues:

<!-- Screen readers announce the access key -->
<button accesskey="s">
Save
</button>
<!-- Announced as: "Save button, access key S" -->

Potential issues:

  • May conflict with screen reader shortcuts (JAWS, NVDA use many key combinations)
  • Not all screen readers announce access keys consistently
  • Users may not know how to use them

For keyboard navigation, tabindex is often better:

<!-- Access key: Quick activation -->
<button accesskey="s" onclick="save()">Save</button>
<!-- Tabindex: Keyboard navigation -->
<div tabindex="0" role="button" onclick="action()">
Custom Control
</div>

Add hints about how to use access keys:

<button
accesskey="s"
title="Save (Alt+S on Windows, Ctrl+Option+S on Mac)">
<u>S</u>ave
</button>

You can detect when an access key is triggered:

document.getElementById('saveBtn').addEventListener('click', (e) => {
// Check if triggered by access key
if (e.detail === 0) {
console.log('Triggered by keyboard');
} else {
console.log('Triggered by mouse');
}
});
// Get all elements with access keys
const elementsWithAccessKeys = document.querySelectorAll('[accesskey]');
elementsWithAccessKeys.forEach(el => {
console.log(`${el.textContent}: ${el.accessKey}`);
});
// Assign access keys dynamically
const buttons = document.querySelectorAll('button');
const keys = ['1', '2', '3', '4', '5'];
buttons.forEach((btn, index) => {
if (keys[index]) {
btn.accessKey = keys[index];
btn.innerHTML = `<u>${keys[index]}</u>${btn.textContent}`;
}
});

Web applications with power users who will learn shortcuts ✓ Data entry forms where speed is critical ✓ Admin interfaces with repeated actions ✓ Custom keyboard shortcuts that complement tabindex navigation

Public websites where users won’t learn shortcuts ✗ Mobile devices where keyboard shortcuts don’t apply ✗ Content-heavy sites where Tab navigation is sufficient ✗ Sites with many languages where key mnemonics don’t translate

// More control over keyboard shortcuts
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
save();
}
});
<!-- Use standard ARIA keyboard patterns -->
<div role="toolbar">
<button>Bold</button>
<button>Italic</button>
</div>
<!-- Better for navigation -->
<nav>
<a href="#" tabindex="0">Home</a>
<a href="#" tabindex="0">About</a>
</nav>
BrowserSupportNotes
ChromeFullAlt + key (Win/Linux), Ctrl+Option+key (Mac)
FirefoxFullAlt+Shift+key (Win/Linux), Ctrl+Option+key (Mac)
SafariFullCtrl+Option+key
EdgeFullAlt + key
MobileLimitedVirtual keyboards don’t support access keys