XML technologies / CSS / CSS Cookbook / Forms / Highlighting keyboard shortcuts in web forms
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to visually highlight a web form’s keyboard shortcuts.
Solution
Use descendant selectors to highlight the characters in the label tag that correspond to keyboard shortcuts.
First, create a CSS rule specifying that text inside em tags within a form should be underlined:
form em {
text-decoration: underline;
font-style: normal;
}To highlight shortcut letters, surround them in the HTML text with em tags as specified by the CSS rule.
<form id="msgform" name="msgform" method="post" action="/process.php">
<label for="fmtitle" accesskey="a"><em>A</em>nrede</label>
<select name="fmtitle" id="fmtitle">
<option value="herr">Herr</option>
<option value="frau">Frau</option>
<option value="firma">Firma</option>
</select>
<label for="fmname" accesskey="n"><em>N</em>ame</label>
<input type="text" name="fmname" id="fmname" />
<label for="fmemail" accesskey="e"><em>E-</em>Mail</label>
<input type="text" name="fmemail" id="fmemail" />
<label for="fmstate" accesskey="b"><em>B</em>undesland</label>
<input type="text" name="fmstate" id="fmstate" />
<label for="fmzip" accesskey="p"><em>P</em>ostleitzahl</label>
<input type="text" name="fmzip" id="fmzip" />
<label for="fmmsg" accesskey="h">Nac<em>h</em>richt</label>
<textarea name="fmmsg" id="fmmsg" rows="5" cols="14"></textarea>
<input type="submit" name="submit" value="Abschicken" class="submit" />
</form>Discussion
Keyboard shortcuts help users with disabilities navigate the different parts of a web page. Underlining shortcut letters makes it easy to see how to navigate the form without a mouse.
The following browsers support keyboard shortcuts: Safari, Internet Explorer for Windows 4+, Mozilla, Firefox, Netscape Navigator 6+ and Opera 7+.
See also
The article “Accesskeys: Unlocking Hidden Navigation” by Stuart Robertson and the recipe Keyboard-controlled navigation menus.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln