Adding keyboard shortcuts to links

With the accesskey attribute, you can assign keyboard shortcuts to links. The idea behind creating keyboard shortcuts is to simply allow the user to quickly visit a page by using the access keys value corresponding to the link. In Windows, use ALT-X (where X represents a numerical value assigned with accesskey attribute) keys from the keyboard to open the desired link.

When defining keyboard shortcuts for links, make sure you include the keyboard shortcuts next to each link. If, however, you do not display the keyboard shortcuts, user won't know you have defined keyboard shortcuts. Thus users cannot use those shortcuts for links!

The following shows how to use the accsskey to define keyboard shortcuts to links:

  • <a href="../asp/Active-Server-Pages.asp" accesskey="1">Start learning ASP</a> (ALT or COMMAND 1)
  • <a href="html.asp" accesskey="2">Start learning HTML</a> (ALT or COMMAND 2)
  • <a href="../javascript/scripting-javascript.asp" accesskey="3">Learn JavaScript</a> (ALT or COMMAND 3)

For the first link above, we assign the accesskey 1 to designate the shortcut ALT 1 in Windows (and COMMAND 1 under MAC) to use this link. For the second link, we set the accesskey to 2 and thus to use this link ALT 2 can be used. Because accesskey attribute is set to 3 for the third link, ALT 3 can be used to activate this link. The following shows the output of the code: