Tuesday, March 3, 2009

KBD tag

kbd is an HTML tag that is used to specify text to be typed in by the user (usually on a keyboard). While seldom used, this tag is useful for writing documentation for computer users. While the tag usually renders text by displaying it in a monospaced font, the tag should not be used simply for this purpose.

See also: code, font, plaintext, pre, samp, tt, var
Attributes

The kbd tag does not have any required HTML attributes. It does, however have numerous allowable attributes including:

* HTML Core Attributes
o class (type: CDATA) - space separated list of classes
o id (type: ID) - document-wide unique id
o style (type: Style Sheet) - associated style information
o title (type: Text) - advisory title/amplification; this information is usually displayed through tooltips

* HTML International Attributes (I18N)
o dir (type: Custom) - specifies the direction of weak or neutral text; valid values include ltr (left to right) or rtl (right to left)
o lang (type: Custom) - specifies the Language Code of the language used in the text

* HTML Event Attributes
o onclick (type: Script) - a pointer button was clicked
o ondblclick (type: Script) - a pointer button was double clicked
o onkeydown (type: Script) - a key was pressed down
o onkeypress (type: Script) - a key was pressed and released
o onkeyup (type: Script) - a key was released
o onmousedown (type: Script) - a pointer button was pressed down
o onmousemove (type: Script) - a pointer was moved within
o onmouseout (type: Script) - a pointer was moved away
o onmouseover (type: Script) - a pointer was moved onto
o onmouseup (type: Script) - a pointer button was released

Usage

To use the kbd tag, simply place opening and closing HTML tags around the characters that should be entered by the user. For example:

To destroy the usefulness of your computer, type del C:\*.* /S /Q at the command prompt.

On browsers that support this tag, this will typically cause the phrase "del *.* /S /Q" to be displayed in a monospaced font. Keep in mind that the purpose of this tag is to specify text to be typed in by the user, not to format your text. If you simply want to use a teletype font, you should technically use Cascading Style Sheets or the pre tag, however there are also the deprecated plaintext, samp, and tt tags that will do this as well.

No comments:

Post a Comment