Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

KBD - keyboard input


To present a particular command or data string to be entered by the user. Typically this is used in instruction manuals.

Typical rendering

Monospaced. See general notes on rendering markup.

Basic syntax


Possible attributes


Allowed context

Text container, i.e. any element that may contain text elements. This includes most HTML elements. In particular, text elements can be nested.


Text elements. Notice that this disallows e.g. paragraph breaks.


Example KBD-1.html:

Finally, type <KBD>logout</KBD> and press the return key.


Use the KBD element for fixed strings only. To indicate input which varies from one case to another, use the VAR element.

Although program code might be regarded as keyboard input (to be typed by a programmer), especially in the context of teaching programming, it is more natural to use the CODE element for code fragments.

It is arguable whether one should use the KBD element for command names (or names of programs) as well, even when they do not appear in a context which discusses how commands are given. One might say that a command name like ls (in Unix) is just a name, not keyboard input. But I recommend using KBD, since it is difficult and sometimes quite artificial to distinguish e.g. ls as keyboard input (or part of it) and as the name of a command (or program). Notice that when a command name appears at the beginning of a statement, grammar rules require a capital initial which might be misleasing (by suggesting to the user that the case of letters in irrelevant on keyboard input); by using KBD - usually rendered using a monospaced font, and therefore distinguishing the command name from normal text - we make it more acceptable to violate the grammar rule.

As usual in HTML, division into lines and the use of blanks and tabs is selected by the browser, not honoring the one in the HTML file. Be careful in telling the user when he should press the return or enter key, since this may not correspond to the visual layout of your instructions.

See also notes on presenting interaction with computer and general remarks on phrase elements.

Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.