accesskey - HTML: HyperText Markup Language 编辑

The accesskey global attribute provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character (which includes accented and other characters that can be generated by the keyboard).

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Note: In the WHATWG spec, it says you can specify multiple space-separated characters, and the browser will use the first one it supports. However, this does not work in most browsers. IE/Edge uses the first one it supports without problems, provided there are no conflicts with other commands.

The way to activate the accesskey depends on the browser and its platform:

WindowsLinuxMac
FirefoxAlt + Shift + keyOn Firefox 57 or newer: Control + Option + key or Control + Alt + key
On Firefox 14 or newer: Control + Alt + key
On Firefox 13 or older: Control + key
Internet ExplorerAlt + key
Alt + Shift + key
N/A
EdgeN/AControl + Option + key
Control + Option + Shift + key
Google ChromeAlt + Shift + key
SafariN/A
Opera 15+Alt + keyControl + Alt + key
Opera 12Shift + Esc opens a contents list which are accessible by accesskey, then, can choose an item by pressing key

Accessibility concerns

In addition to poor browser support, there are numerous concerns with the accesskey attribute:

  • An accesskey value can conflict with a system or browser keyboard shortcut, or assistive technology functionality. What may work for one combination of operating system, assistive technology, and browser may not work with other combinations.
  • Certain accesskey values may not be present on certain keyboards, especially when internationalization is a concern. So adapting to specific languages could cause further problems.
  • accesskey values that rely on numbers may be confusing to individuals experiencing cognitive concerns, where the number doesn't have a logical association with the functionality it triggers. 
  • Informing the user that accesskeys are present, so that they are aware of the functionality. If the system lacks a method of notifying the user about this feature, the user might accidentally activate accesskeys.

Because of these issues, it is generally advised not to use accesskeys for most general-purpose websites and web apps.

Specifications

SpecificationStatusComment
HTML 5.2
The definition of 'accesskey' in that specification.
RecommendationMore realistic behavior described for what is implemented in reality.
HTML Living Standard
The definition of 'accesskey' in that specification.
Living StandardNo change from latest W3C HTML 5.1 spec.
HTML 5.1
The definition of 'accesskey' in that specification.
RecommendationNo change from HTML5.
HTML5
The definition of 'accesskey' in that specification.
RecommendationFrom HTML 4.01 Specification, several characters can now be set as the accesskey. Also, it can be set on any element.
HTML 4.01 Specification
The definition of 'accesskey' in that specification.
RecommendationOnly supported on <a>, <area>, <button>, <input>, <label>, <legend> and <textarea>

Browser compatibility

BCD tables only load in the browser

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:63 次

字数:8990

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文