XHTML » XHTML Core Tag » accesskey

Syntax:
accesskey="character"

The accesskey attribute allows you to designate a character on the keyboard that when pressed, along with the alt or meta key, will bring focus to an HTML element. By focus, we mean that the cursor will go to that element (for example, a link or an input box in a form).

The character can be any single character on the keyboard, including upper and lower case alphabets, numbers, symbols, or punctuation marks. You cannot repeat a character since each accesskey must uniquely identify an element.
 

Examples

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML accesskey attribute example</title>
</head>
<body>
<form>
Simultaneously press the alt and 1 buttons and the cursor goes to the First Name input box.
<br />
Simultaneously press the alt and 7 buttons and the cursor goes to the Last Name input box.
<br />
Simultaneously press the alt and r buttons and the cursor goes to the Maiden Name input box.
<br />
<hr />
<br />
First Name: (accesskey = 1)
<br />
<input type="text" name="firstlname" size="30" accesskey="1" />
<br />
Last Name: (accesskey = 7)
</br>
<input type="text" name="lastname" size="30" accesskey="7" />
<br />
Maiden Name: (accesskey = r)
<br />
<input type="text" name="maidenname" size="30" accesskey="r" />
</form>
</body>
</html>
Output:
Simultaneously press the alt and 1 buttons and the cursor goes to the First Name input box.
Simultaneously press the alt and 7 buttons and the cursor goes to the Last Name input box.
Simultaneously press the alt and r buttons and the cursor goes to the Maiden Name input box.


First Name: (accesskey = 1)

Last Name: (accesskey = 7)

Maiden Name: (accesskey = r)
Language(s): XHTML

See Also: