Html Computer Code Elements

How to use computer code elements in HTML?

Explanation

HTML Computer Code Formatting

In HTML, the letter sizing and spacing is variable. But, in the case of the HTML page displaying a computer code, it is not necessary to use letters with variable size and spacing. A fixed spacing and size of the letters are required when displaying examples of computer code. Hence to display computer codes and programming languages in HTML pages, the tags <kbd>, <samp>, and <code> are used to display letters with fixed size and spacing.
HTML <kbd> For Keyboard Input :

<kbd> </kbd>
The HTML <kbd> element defines keyboard input.

Example:



<kbd>This text represents keyboard input.</kbd>

Result :
This text represents keyboard input.

HTML <samp> For Computer Output ::

<samp> </samp>
The HTML <samp> element defines sample output from a computer program.
Example :
<p>The below samp element represents sample output format of a computer program:</p>
<samp>
Last login: Wed Sep 16 18:24:52 IST 2015 on pts/10<br>
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-74-generic i686)<br>
* Documentation: https://help.ubuntu.com/
</samp>

Result :

The below samp element represents sample output format of a computer program:
Last login: Wed Sep 16 18:24:52 IST 2015 on pts/10
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-74-generic i686)
* Documentation: https://help.ubuntu.com/


HTML <code> For Computer Code :

<code> </code>
The HTML <code> element defines a piece of programming code.

Example:



<p>Programming code example:</p>

<code>
var x = 7;
var y = 10;
document.write = x + y;
</code>

Result :

Programming code example:



var x = 7;
var y = 10;
document.write = x + y;


Ask Questions

Ask Question