The Preformatted Text element presents blocks of text in fixed-width font, and so is suitable for text that has been formatted on screen, or formatted for a mono-spaced font.
The <PRE>
element may be used with the optional WIDTH attribute, which is a HTML Level 1 feature. The WIDTH
attribute specifies the maximum number of characters for a line and allows the HTML user agent to determine which of its available fonts to use and how to indent the text (if at all). If the WIDTH
attribute is not present, a width of 80 characters is assumed. Where the WIDTH
attribute is supported, widths of 40, 80 and 132 characters should be presented optimally, with other widths being rounded up.
Within preformatted text, any line breaks within the text are rendered as a move to the beginning of the next line. The <P>
element should not be used, but if it is found, it should be rendered as a move to the beginning of the next line. It is possible to use Anchor elements and character highlighting elements are allowed. Elements that define paragraph formatting (headings, address, etc.) must not be used. The horizontal tab character (encoded in US-ASCII and ISO-8859-1 as decimal 9) represents a special formatting case. It should be interpreted as the smallest positive nonzero number of spaces which will leave the number of characters so far on the line as a multiple of 8. (However, despite being allowed, its use is not recommended.)
NOTE: It is at the discretion of individual browsers how to render preformatted text and where "beginning of a new line" is to be implied, the browser can render that new line indented if it sees fit.
Example of use:
<PRE WIDTH="80">
This is an example of preformatted text.
</PRE>
NOTE: Within a Preformatted Text element, the constraint that the rendering must be on a fixed horizontal character pitch may limit or prevent the ability of the browser to render highlighting elements (such as <B>
, <I>
etc.) specially.
<PRE>
can also take the CLASS, ID and STYLE attributes to allow style sheet definitions to be applied to it. For more details of these attributes, see the Style Sheets topic.