Learn HTMLWeb Design & DevelopmentWebsite

Class 6 | Computer Code | Learn HTML

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:

<p>To open a file, select:</p>
<p><kbd>File | Open...</kbd></p>

HTML Sample Formatting

The HTML <samp> element defines a computer output:

<samp>
demo.example.com login: Apr 12 09:10:17Linux 2.6.10grsec+gg3+e+fhs6b+nfs+gr0501
</samp>

HTML Code Formatting

The HTML <code> element defines programming code:

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

HTML Variable Formatting

The HTML <var> element defines a mathematical variable:

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

Leave a Reply

Your email address will not be published. Required fields are marked *