Skip to navigation

malevolent design weblog

This blog is now defunct, but you can find more stuff over at my personal site

Finishing Touches: Styled Keys

The seldom-seen kbd tag indicates text to be entered by the user. When styled appropriately, it can be handy for displaying things such as keyboard controls. See this site’s accessibility page for an example.

I’m currently using this CSS for a buttonish appearance:

	font-family:'andale mono','lucida console','courier new',monospace;
	b\order:1px solid #dddddd;

The backslashes are there to hide some styling from older browsers such as IE 5.x; this technique is known as the Simplified Box Model Hack, and is one of the few CSS hacks a developer needs to know nowadays.

If you’re using the kbd tag for entire strings of command-line input (its primary intended use, judging from most examples) rather than just individual keys then the above styling probably isn’t quite appropriate; an additional class could be applied for single keys, or the effect applied to spans nested within kbd. It could also be argued that it’s not semantically correct to apply the tag to descriptions of keys rather than just literal text (e.g. Ctrl isn’t telling you to type C, t, r then l), but it’s hard to nitpick productively over such cases without authoritative examples.


Comments are now closed for this entry.