O'Reilly logo

Dynamic HTML: The Definitive Reference by Danny Goodman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

<PRE> — NN all IE all HTML all

Synopsis

<PRE>...</PRE>

End Tag: Required

The PRE element defines a block of preformatted text. Preformatted text is usually rendered by default in a monospace font and, more importantly, it preserves the whitespace (multiple spaces between words and new lines) entered into the source code for the content. Unlike the deprecated PLAINTEXT element, the PRE element doesn’t ignore HTML tags. Instead, it passes such tags onto the browser for normal rendering. If you want to display HTML tags in a block of preformatted text, use entities for the less-than (&lt;) and greater-than (&gt;) symbols. This prevents them from being interpreted as genuine tags but renders the symbols within the preformatted text block.

Browsers are supposed to ignore a whitespace line break immediately following a PRE element start tag in case you wish to start the content on a new line in the source code. By and large, the Version 4 browsers follow this rule (with the exception of IE 4 for the Mac).

The HTML 4.0 specification is adamant about the PRE element maintaining its monospaced font size and line spacing. It lists the following elements that should not be included inside a PRE element: APPLET, BASEFONT, BIG, FONT, IMG, OBJECT, SMALL, SUB, and SUP. Any one of these destroys the fixed-size pitch of the PRE element. The recommendation also encourages authors to avoid overriding the monospaced font settings with style sheets.

One last admonition concerns using tab characters ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required