HTML Computer Code Elements
HTML <kbd> For Keyboard Input
The HTML <kbdb> element represents user input, like keyboard input or voice commands.
Text surrouded by <kbd> tags is typically displayed in the browser’s default monospace font:
<p>Save the document by pressing <kbd>Ctrl + S</kbd></p>
HTML <samp> For Program Output
The HTML <samp> element represents output from a program or computing system.
Text surrounded by <samp> tags is typically displayed in the browser’s default monospace font:
<p>If you input wrong value, the program will return <samp>Error!</samp></p>
HTML <code> For Computer Code
The HTML <code> element defines a fragment of computer code.
Text surrounded by <code> tags is typically displayed in the browser’s default monospace font:
<code>
x = 5;
y = 6;
z = x + y;
</code>
Get Caio Martins’s stories in your inbox
Join Medium for free to get updates from this writer.
Result;
x = 5; y = 6; z = x + y;
Notice that the <code> element does not preserve extra withesace and line-breaks.
To fix this, you can ut the <code> element inside a <pre> element:
<pre>
<code>
x = 5;
y = 6;
z = x + y;
</code>
</pre>
Result:
x=5;
y=6;
z=x+y;
HTML <var> For Variables
The HTML <var> element defines a variable.
The variable could be a variable in a mathematical expression or a variable in programming context:
Einstein wrote: <var>E</var> = <var>mc</var><sup>2</sup>.






