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:

<p>Save the document by pressing <kbd>Ctrl + S</kbd></p>

Output

Save the document by pressing Ctrl + S

It is also used for style, kbd html coding and class, what is the full form and meaning of kbd, function of kbd, purpose of kbd tag in html.

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:

<p>Message from my computer:</p>
<p><samp>File not found.<br />Press F1 to continue</samp></p>

Output

Message from my computer:

File not found.
Press F1 to continue

It is also used for samp element, samp vs code, samp tag purpose, samp tag full form and meaning, what does samp tag do in html, why samp tag is used in html.

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:

<code>
x = 5;
y = 6;
z = x + y;
</code>

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

<pre>
<code>
x = 5;
y = 6;
z = x + y;
</code>
</pre>

Output

x = 5;
y = 6;
z = x + y;

It is also used for code element line break, code element style, code element syntax highlighting, code element example, code element indent, code element width.

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:

<p>The area of a triangle is: 1/2 x <var>b</var> x <var>h</var>,
where <var>b</var> is the base, and <var>h</var> is the vertical height.</p>

Output

The area of a triangle is: 1/2 x b x h, where b is the base, and h is the vertical height.

It is also used for var tag code, var element example, var tag attributes, var tag usage, var value, var id, var length