Preformatted Text

Text in which spaces, tabs, and line feeds must be preserved. Content is typically displayed in monofont to preserve character alignment.


The <preformat> element is typically used for machine-related communication such as computer code and error messages, in which whitespace such as tabs, line feeds, and spaces should be preserved.

Position: The @position attribute may be used to indicate whether this element must be anchored at its exact location within the text, or whether it may float, for example, to the top of the next page, next column, to the end of a logical file, or within a separate window. For the typical <preformat> element, the “float or anchor” decision will be governed by the size of the object. For example, short code fragments are typically anchored whereas full programs are typically placed elsewhere such as in a separate window or at the end of the document.


id Document Internal Identifier
orientation Orientation
position Position
preformat-type Type of Preformatted Text
specific-use Specific Use
xml:base Base
xml:lang Language
xml:space Space

Related Elements

Best Practice: Although poetry may be tagged with the <preformat> element if spacing is critical, this element is not intended for poetry. Poetry and verse should usually be tagged with the <verse-group> element, which may not preserve the exact indentation, but is likely to be displayed in a proportional font. Similarly, this element is not intended for equations and math.

Content Model

<!ELEMENT  preformat    %preformat-model;                            >

Expanded Content Model

(#PCDATA | alt-text | long-desc | email | ext-link | uri | inline-supplementary-material | related-article | related-object | hr | bold | fixed-case | italic | monospace | overline | overline-start | overline-end | roman | sans-serif | sc | strike | underline | underline-start | underline-end | ruby | alternatives | inline-graphic | private-char | chem-struct | inline-formula | tex-math | mml:math | abbrev | milestone-end | milestone-start | named-content | styled-content | fn | target | xref | sub | sup | x | attrib | permissions)*


Any combination of:

This element may be contained in:

<abstract>, <ack>, <alternatives>, <app>, <app-group>, <bio>, <body>, <boxed-text>, <chem-struct>, <chem-struct-wrap>, <disp-formula>, <disp-quote>, <fig>, <floats-group>, <glossary>, <license-p>, <named-content>, <notes>, <p>, <ref-list>, <sec>, <styled-content>, <supplementary-material>, <table-wrap>, <td>, <term>, <th>, <trans-abstract>

Example 1

<article dtd-version="1.1d1">
<p>Trees, of course, are hardly a random choice for our
methodology. ... Hierarchical trees have been understood as a
way of viewing document structures since the earliest days of
SGML development. Our initial tree structure was very simple:
&lt;!ELEMENT  implications  (tree+) &gt;
&lt;!ELEMENT  tree          (root, branches) &gt;
&lt;!ELEMENT  root          (term, synonym?) &gt;
&lt;!ELEMENT  branches      (term | (term, synonym) | tree)* &gt;
Terms are the literal strings for which the Ferret engine searches; they
are the most specific expressions to be found in real documents of the
concepts on which classifications rules act.</p>

Example 2

<p>As you can see in the following excerpt, use of literal
result elements is very convenient:
&lt;xsl:template match="div/divhead" priority="2"&gt;
  &lt;<named-content content-type="literal result">h2</named-content>&gt;
  &lt;<named-content content-type="literal result">/h2</named-content>&gt;