ToC ~ Up ~ Prev ~ Next ~ Index Introduction to HTML
Last Update: 5 January 1998

4.9 Preformatted Text

The PRE element is used to enclose text to be displayed with a fixed width typewriter-like font. This is useful for presenting text that has been formatted for a teletype, or for a fixed width character display. It is also commonly used to present typed computer code examples.

In particular, as HTML 2.0 did not contain a TABLE element, the PRE element was the only way in which structured tables could be properly displayed on most current browsers.

HTML now supports tables, and TABLEs are now supporteed by almost all browsers. This is discussed in the TABLES documentation.

PRE takes one optional attribute: WIDTH. This supposedly specifies the maximum number of characters that can be displayed on a single line. However, most browsers ignore this attribute completely. It is likely that the WIDTH attribute will be dropped in subsequent versions of HTML.

You can include character emphasis elements (EM, STRONG, B, I, etc.) as well as hypertext anchors within a PRE.

Things to Avoid
You should NOT use elements that define paragraph formatting within the PRE element. This means you should not use <P>, <ADDRESS>, <Hn> and so on. You should avoid the use of tab characters -- use single blank characters to space text apart.
Things That are OK
You can use Anchor. A typed carriage return will cause a new line in the presented text.

4.9.1 Example of PRE

The following text:

<PRE WIDTH=30>
   Hi there.  This is a rather <EM>stupid</EM> example.
   Lord only knows what I was thinking at the time.  I 
   suppose I should get more sleep when I do this stuff. But 
   why should I try and write Shakespearean sonnets when it is 
   just a stupid example of the <A HREF="pre.html">PRE</A> element!
</PRE>
is rendered:
   Hi there.  This is a rather stupid example.
   Lord only knows what I was thinking at the time.  I 
   suppose I should get more sleep when I do this stuff. But 
   why should I try and write Shakespearean sonnets when it is 
   just a stupid example of the PRE element!


ToC ~ Up ~ Prev ~ Next ~ Index Introduction to HTML
© 1994-1998 by Ian Graham
Last Update: 5 January 1998