HTML global attribute accesskey








The accesskey attribute sets one or more keyboard shortcuts that will select the element.

accesskey attributes are added to three input elements.

This enables users to use keyboard shortcuts to move between used elements.

The key combination required to trigger the accesskey setting differs between platforms.

For Windows, it is the Alt key and the accesskey value pressed together.

  • press Alt+n to focus on the first input element and enter my name.
  • press Alt+p to focus on the second input element and enter my password.
  • press Alt+s to focus on Log In button, which submits the form.




Syntax

<element accesskey="character">

Attribute Values

character
shortcut key to activate the element

Browser compatibility

accesskey Yes Yes Yes Yes Yes

Example

The following code uses accesskey attribute in a simple form.

<!DOCTYPE HTML>
<html>
    <body>
        <form>
            Name: <input type="text"  name="name" accesskey="n"/>
            <p/>
            Password: <input  type="password" name="password"  accesskey="p"/>
            <p/>
            <input type="submit" value="Log  In"  accesskey="s"/>
        </form>
    </body>
</html><!-- w ww  .  j a v  a 2 s.c o m-->

Click to view the demo