HTML computer code elements

Computerkode

var person = {
    firstName:"Bill",
    lastName:"Gates",
    age:50,
    eyeColor:"blue"
}

HTML computerkodeformat

Normalt bruger HTMLVariabelbogstavsstørrelse samt variabelt mellemrum.

ViserComputerkodeI eksempler er det ikke nødvendigt.

<kbd>, <samp>, samt <code> Alle elementer understøtter faste bogstavsstørrelser og mellemrum.

HTML tastaturformat

HTML <kbd> Element definitionTastaturindtastning:

Example

<p>Åbn en fil ved at vælge:</p>
<p><kbd>File | Open...</kbd></p>

Try it yourself

HTML sample format

HTML <samp> Element definitionComputer output example:

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>

Try it yourself

HTML code formatting

HTML <code> Element definitionProgramming code example:

Example

<code>
var person = { firstName:"Bill", lastName:"Gates", age:50, eyeColor:"blue" }
</code>

Try it yourself

<code> elementdo not preserveextraspacesandLine breaks:

Example

Code example:

<code>
var person = {
    firstName:"Bill",
    lastName:"Gates",
    age:50,
    eyeColor:"blue"
}
</code>

Try it yourself

To solve this problem, you must enclose the code within the <pre> element:

Example

Code example:

<code>
<pre>
var person = {
    firstName:"Bill",
    lastName:"Gates",
    age:50,
    eyeColor:"blue"
}
</pre>
</code>

Try it yourself

HTML variable formatting

HTML <var> Element definitionMathematical variables:

Example

<p>Einstein wrote:</p>
<p><var>E = m c<sup>2</sup></var></p>

Try it yourself

HTML computer code elements

Tag Description
<code> Define computer code text
<kbd> Define keyboard text
<samp> Define computer code examples
<var> Define variables
<pre> Define preformatted text