Sunday 12 April 2015

HTML Computer Code Elements

{"uid":1,"hostPeerName":"http://www.w3schools.com","initialGeometry":"{\"windowCoords_t\":0,\"windowCoords_r\":1349,\"windowCoords_b\":667,\"windowCoords_l\":0,\"frameCoords_t\":135,\"frameCoords_r\":967.828125,\"frameCoords_b\":225,\"frameCoords_l\":239.828125,\"styleZIndex\":\"auto\",\"allowedExpansion_t\":135,\"allowedExpansion_r\":381.171875,\"allowedExpansion_b\":442,\"allowedExpansion_l\":239.828125,\"xInView\":1,\"yInView\":1}","permissions":"{\"expandByOverlay\":true,\"expandByPush\":false,\"readCookie\":false,\"writeCookie\":false}","metadata":"{\"shared\":{\"sf_ver\":\"1-0-2\",\"ck_on\":1,\"flash_ver\":\"17.0.0\"}}","reportCreativeGeometry":false}" scrolling="no" marginwidth="0" marginheight="0" width="728" height="90" data-is-safeframe="true" style="box-sizing: border-box; border-width: 0px; vertical-align: bottom;">

HTML Computer Code Elements


Computer Code

var person = {
    firstName:"John",
    lastName:"Doe",
    age:50,
    eyeColor:"blue"
}

HTML Computer Code Formatting

Normally, HTML uses variable letter size, and variable letter spacing.
This is not wanted when displaying examples of computer code.
The <kbd><samp>, and <code> elements all support fixed letter size and spacing.

HTML Keyboard Formatting

The HTML <kbd> element defines keyboard input:

Example

<p>To open a file, select:</p>

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

Try it Yourself »

HTML Sample Formatting

The HTML <samp> element defines a computer output:

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

The HTML <code> element defines programming code:

Example

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

Try it Yourself »
The <code> element does not preserve extra whitespace and line-breaks:

 Example

<p>Coding Example:</p>

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

Try it Yourself »
To fix this, you must wrap the code in a <pre> element:

 Example

<p>Coding Example:</p>

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

Try it Yourself »

HTML Variable Formatting

The HTML <var> element defines a mathematical variable:

Example

<p>Einstein wrote:</p>

<p><var>E = m c<sup>2</sup></var></p>

Try it Yourself »

HTML Computer Code Elements

TagDescription
<code>Defines programming code
<kbd>Defines keyboard input 
<samp>Defines computer output
<var>Defines a mathematical variable
<pre>Defines preformatted text


COLOR PICKER

colorpicker

No comments:

Post a Comment

>