Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

CODE - program code

Purpose

To present program code.

Typical rendering

Monospaced. See general notes on rendering markup.

Basic syntax

<CODE>text</CODE>

Possible attributes

None.

Allowed context

Text container, i.e. any element that may contain text elements. This includes most HTML elements. In particular, text elements can be nested.

Contents

Text elements. Notice that this disallows e.g. paragraph breaks.

Examples

The following example discusses the C programming language, referring to a particular expression in that language:

Example CODE-1.html:

Expressions like <CODE>a[i++] + b[i++]</CODE> should not be used,
since they cause undefined behavior.

Notes

As usual in HTML, division into lines and the use of blanks and tabs is selected by the browser, not honoring the one in the HTML file. Thus, large program codes are more suitably presented using the PRE element or as separate text files to which you have links in HTML files.

See also notes on presenting interaction with computer and general remarks on phrase elements.



Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.