WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML Computer Code Elements

Computer Code Element

<code>
var x = 5;
var y = 6;
document.getElementById("demo").innerHTML = x + y;
</code>

HTML Computer Code Formatting

HTML typically utilizes variable letter measure and spacing.

This isn't needed while showing instances of PC code.

The <kbd>, <samp>, and <code> components all help fixed letter estimate what's more, spacing.


HTML <kbd> For Keyboard Input

The HTML <kbd> component characterizes console input:

Example

<kbd>File | Open...</kbd>

Result:

File | Open...
Try it Yourself »

HTML <samp> For Computer Output

The HTML <samp> component characterizes test yield from a PC program:

Example

<samp>
demo.example.com login: Apr 12 09:10:17
Linux 2.6.10-grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189
</samp>

Result:

demo.example.com login: Apr 12 09:10:17 Linux 2.6.10-grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189
Try it Yourself »

HTML <code> For Computer Code

The HTML <code> component characterizes a bit of programming code:

Example

<code>
var x = 5;
var y = 6;
document.getElementById("demo").innerHTML = x + y;
</code>

Result:

var x = 5; var y = 6; document.getElementById("demo").innerHTML = x + y;
Try it Yourself »

Notice that the <code> component does not safeguard additional whitespace and line-breaks.

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

Example

<pre>
<code>
var x = 5;
var y = 6;
document.getElementById("demo").innerHTML = x + y;
</code>
</pre>

Result:

var x = 5; 

var y = 6; 

document.getElementById("demo").innerHTML = x + y; 

Try it Yourself »

HTML <var> For Variables

The HTML <var> component characterizes a variable.

The variable could be a variable in a scientific articulation or a variable in programming context:

Example

Einstein composed: <var>E</var> = <var>m</var><var>c</var><sup>2</sup>.

Result:

Einstein composed: E = mc2.
Try it Yourself »