HTML Computer Code

HTML <kbd>

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.

HTML Code:

<p>The kbd element represents user input:</p> <p>Save the document by pressing <kbd>Ctrl + S</kbd></p>

Result:

The kbd element represents user input:

Save the document by pressing Ctrl + S


HTML <samp>

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.

HTML Code:

<p>The samp element represents output from a program or computing system:</p> <p>If you input wrong value, the program will return <samp>Error!</samp></p>

Result:

The samp element represents output from a program or computing system:

If you input wrong value, the program will return Error!


HTML <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.

HTML Code:

<p>Programming code example:</p> <code> x = 5; y = 6; z = x + y; </code>

Result:

Programming code 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.

HTML Code:

<p>To fix this, you can put the code element inside a pre element:</p> <pre> <code> x = 5; y = 6; z = x + y; </code> </pre>

Result:

To fix this, you can put the code element inside a pre element:

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

HTML <var>

The HTML <var> element defines a variable.

The variable could be a variable in a mathematical expression or a variable in programming context.

HTML Code:

<p>Einstein wrote: <var>E</var> = <var>mc</var><sup>2</sup>.</p>

Result:

Einstein wrote: E = mc2.

HTML Index

References

  1. W3Schools

This page is only a summary of the material from W3Schools. Definitions, Examples and Codes are exclusive property of W3Schools.