HTML | accesskey Attribute

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

Syntax:

<element accessKey = "single_character">

Shortcut to use access key: The table describes the shortcut to use access key.



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 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

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
Before using the access key:
accesskey
After using the access key:

Supported Browsers: The browser supported by accesskey attribute are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.