HTML Computer Code Elements
Computer Code
x = 5; y = 6; z = x + y;
HTML <kbd> For Keyboard Input
The HTML <kbd>
element represents user input, like keyboard input or voice commands.
Text surrounded by <kbd>
tags is typically displayed in the browser’s default monospace font:
Example
Save the document by pressing Ctrl + S
Result:
Save the document by pressing Ctrl + S
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:
Example
If you input wrong value, the program will return Error!
Result:
If you input wrong value, the program will return Error!
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:
Example
x = 5;y = 6;z = x + y;
Notice that the <code>
element does not preserve extra whitespace and line-breaks.
To fix this, you can put the <code>
element inside a <pre>
element:
Example
x = 5;y = 6;z = x + y;
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:
Example
Einstein wrote: E = mc2.
Result:
Leave A Comment