Attributes Relative to the Keyboard
accesskey
HTML offers the accesskey attribute to specify a shortcut key to activate or bring focus to an element. This can make navigation more efficient for keyboard-only users.
HTML5 allows this attribute to be used on any element, but it's particularly useful when it's used with interactive ones. This includes links, buttons, and form controls.
<button accesskey="b">Important Button</button>
参考资料:
tabindex
- When tabindex is on a tag, it indicates that element can be focused on.
- Certain elements, such as links and form controls, automatically receive keyboard focus when a user tabs through a page.
- his same functionality can be given to other elements, such as
div
,span
, andp
, by placing atabindex="0"
attribute on them.
<div tabindex="0">I need keyboard focus!</div>
<div tabindex="1">I get keyboard focus, and I get it first!</div>
<div tabindex="2">I get keyboard focus, and I get it second!</div>
参考资料: