The Wayback Machine - https://web.archive.org/web/20240624101219/https://www.geeksforgeeks.org/html-accesskey-attribute/
Open In App

HTML accesskey Attribute

Last Updated : 07 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The accesskey attribute in HTML is the keyboard shortcut to activate/focus specific elements. The access key attribute is browser-dependent. It may vary from browser to browser.

Supported Tags: It supports all HTML elements. 

Syntax

<element accessKey = "single_character">

Shortcut to use accesskey

The table describes the shortcut to use accesskey.  

Browser Windows Mac Linux
Google Chrome Alt + single_character Command + Alt + single_character Alt + single_character
Mozilla Firefox Alt + Shift + single_character

Command + Alt + single_character (On Firefox 14 or newer)

Command + single_character (On Firefox 13 or older)

Alt + Shift + single_character
Internet Explorer Alt + single_character N/A N/A
Safari Alt + single_character Command + Alt + single_character N/A
Opera 15+ Alt + single_character Command + Alt + single_character Alt + single_character

Note:  

  • In HTML4.1, the accesskey attributes can be used with only a few elements which include <a>, <area>, <button>, <input>, <label>, <legend>, and <textarea>.
  • In HTML5, the accesskey attribute can be used with any element.

The behavior of the browser differs when dealing with more than one element having the same accesskey:

  • Google Chrome and Safari: The last element with the accesskey will be activated
  • Opera: The first element with the accesskey will be activated
  • Internet Explorer and Mozilla Firefox: The next element with the accesskey will be activated

HTML accesskey Attribute Example

Example: In this example demonstrates the use of the accesskey attribute, which assigns the keyboard shortcut “g” to the link. Users can access the linked page by pressing the specified key combination.

html




<!DOCTYPE html>
<html>
    <head>
        <title>accesskey attribute</title>
    </head>
 
    <body>
        <h2>HTML accesskey attribute</h2>
 
        <!-- The accesskey attribute used here -->
        <a
            href="https://ide.geeksforgeeks.org/tryit.php"
            accesskey="g"
            >GeeksforGeeks
        </a>
    </body>
</html>


Output: 

accessKey.gif

Supported Browsers:

The browser supported by accesskey attribute are listed below: 



Previous Article
Next Article

Similar Reads

HTML DOM accessKey Property
The DOM accessKey property is used to set or return the accesskey attribute of an element. Syntax : For Set the accessKey :HTMLElementObject.accessKey = valueFor Return the accessKey :HTMLElementObject.accessKey Value: character: A character that is used to specify the shortcut key. Return Value: This will return the selected element with the attac
2 min read
Web API ButtonElement.accessKey Property
The HTML ButtonElement.accessKey property is used to return a DOMString which is a single character representing the accessKey in the given button. Syntax: ButtonElement.accessKey Return Value: This property returns a DOMString which is a single character representing the accessKey to the given button. Example 1: C/C++ Code &lt;h1 style=&quot;color
1 min read
How href attribute is different from src attribute in HTML ?
In HTML5, the href and src attributes play distinct roles in defining paths or URLs, each associated with specific HTML elements. The href attribute, commonly found in an anchor (&lt;a&gt;) elements, points to the destination of hyperlinks, facilitating navigation. The src attribute, used with elements like &lt;img&gt; and &lt;script&gt;, specifies
1 min read
When to use the class attribute and the id attribute ?
The class attribute is used when multiple HTML elements share a common style or behaviour, allowing the application of a shared style to several elements. It promotes code reusability and is suitable for elements with similar characteristics. The id attribute is utilized when a unique identifier is needed for a specific HTML element. This identifie
1 min read
How to use the target attribute and the rel attribute in the &lt;a&gt; Tag ?
The target and rel attributes in the &lt;a&gt; (anchor) tag is used to control the behaviour of hyperlinks, specifying how the linked content should be opened and establishing relationships between the current and linked documents. Here's how to use these attributes: target Attribute:The target attribute determines where the linked content will be
2 min read
HTML | &lt;html&gt; xmlns Attribute
The HTML &lt;html&gt; xmlns Attribute is used to specify the xml namespace for a document. Important Note: This attribute is mainly required in XHTML, not valid in HTML 4.01, and optional in HTML 5. Syntax: &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; Attribute Values: https://www.geeksforgeeks.org/ It defines the namespace to use (for XHTML d
1 min read
HTML | scoped Attribute
The HTML scoped attribute is a boolean attribute that is used to specify that the styles only apply to this element's parent element and that element's child elements (not the entire document).Note : It is a deprecated attribute and it is not supported by HTML5. Supported tag: style Example: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head
1 min read
HTML | &lt;th&gt; valign Attribute
The HTML &lt;th&gt; valign Attribute is used to specify the vertical alignment of text content in a header cell. It is not supported by HTML 5. Syntax: &lt;th valign="top | middle | bottom | baseline"&gt; Attribute Value: top: It sets the table header content to top-align. middle: It sets the table header content to middle-align. bottom: It sets th
1 min read
HTML | &lt;col&gt; align Attribute
The HTML &lt;col&gt; align Attribute is used to set the horizontal alignment of text content inside the col element. It is not supported by HTML 5. Syntax: &lt;col align="left | right | center | justify | char"&gt; Attribute Values: left: It sets the text left-align. right: It sets the text right-align. center: It sets the text center-align. justif
1 min read
HTML | poster Attribute
The HTML poster Attribute is used to display the image while video downloading or when the user clicks the play button. If this image not set then it will take the first frame of video as a poster image.Applicable: It is mainly used in &lt;video&gt; element. Syntax: &lt;video poster="URL"&gt; Attribute Values: It contains a single value URL which s
1 min read
three90RightbarBannerImg