HTML Computer Code Elements
HTML has a unique formatting and text style to display for defining user input, mathematical expression, and computer programming-related code.
HTML <kbd> Element
The HTML kbd
element is used to define keyboard input keys which indicates text to be entered by the user from keyboard.
The content inside kbd
element displayed as mono-space font.
Example
Define some text as keyboard input in a document:
Save the document by pressing Ctrl + S
Output
HTML <samp> For Program Output
The HTML samp
(short for sample) element is used to define sample results (only text-based output) from a computer program or computer scripts, etc.
The content inside samp
element displayed as mono-space font.
Example
Define some text as sample output from a computer program in a document:
Message from my computer:
File not found.
Press F1 to continue
Output
File not found.
Press F1 to continue
Related Links
HTML <code> For Computer Code
The HTML code
element is used to define a fragment of computer programming code.
For example, a code of HTML or javascript, python or PHP, or some other programming language code.
The content inside code
element displayed as mono-space font.
Example
Define some text as computer code in a document:
x = 5;
y = 6;
z = x + y;
Output
x = 5;
y = 6;
z = x + y;
Note that the element code
doesn't maintain additional whitespace and line breaks.
To correct this, inside a pre
element you can insert the code
element.
Example
x = 5;
y = 6;
z = x + y;
Output
y = 6;
z = x + y;
Related Links
HTML <var> For Variables
The HTML var
(short for variable) element is used to define
a variable name in a computer code or in a mathematical equation.
Typically, the contents inside are shown in italic.
Example
Define some text as variables in a document:
The area of a triangle is: 1/2 x b x h,
where b is the base, and h is the vertical height.
Output