HTML Encyclopaedia

The code tag

The HTML container element
<code> ... </code>
is used for "code" extracts from programs etc.

It renders text (in a monopitch typeface) as entered but line layout is not honoured. HTML special characters have to be escaped. The effect of including block elements within a <code> element is unspecified.

Here is an example

Line 1 <a href=title.html>title</a> Line 2 Line 3

Here is the HTML for the example above

Line 1
&lt;a href=title.html&gt;title&lt;/a&gt;
Line 2
Line 3
<code>
Notice that this is not the same as pre-formatted text.

It can also be used within running text thus: a sample of text.


Browsers

There are significant variations. All browsers use a constant pitch (non-proportional) typeface. MOS3 uses a bold typeface of larger than normal size, ARA, NN3 and IE use a normal typeface of less than normal size. OP2's typeface is of almost normal size.

The inclusion of block elements also has variable results. MOS3, IE3 and ARA all use the distinctive typeface even within <table> elements. OP2 stops using the distinctive typeface as soon as any block element is encountered.


See also <samp>, <kbd>, <dfn>, <var>, <cite> and the general notes on text styles.

Note On many browsers this tag and the others mentioned immediately above, all have exactly the same effect. Differences are purely historical.