Webpage Workshop: Home » HTML language reference » Preformatted text

Preformatted text

This element is used to create blocks of text that are preformatted. This means that spaces, tabs, newlines and other formatting characters are preserved within the text. Most browsers will display this text in a monospaced font.

<pre
    class="class name(s)"
    dir="ltr | rtl"
    id="unique identifier"
    lang="language code"
    style="style information"
    title="text"
    width="number"**
>
</pre>

Key:
‡ = Required attribute
** = Transitional only

Explanation of attributes

class: used to state which class(es) the element belongs to. It is possible to indicate more than one class for an element by separating each class name with a space character. This attribute is normally used in combination with a stylesheet in order to associate the elements with particular styles defined within the stylesheet.

dir: used to set the direction of the text in combination with the language set in the lang attribute. The available values are "ltr" (left to right) and "rtl" (right to left), with the default value being "ltr".

id: used to specify a unique alphanumeric identifier to the element. This is usually used in combination with stylesheets in order to apply a style to one particular instance of an element. Only one element, regardless of type, can be given a particular id.

lang: used to indicate the language being used in the text contained within the element. The value of this attribute takes on the form of the ISO standard lanuage abbreviations found in RFC 3066. A list of these codes can be found on the ISO language codes page.

style: used to specify an inline style to apply to the element. The styles defined here override the styles declared in the header section.

title: used to define an advisory text that may be displayed as a tooltip when a mouse is used to hover over the element.

width**: this attribute is used to specify the width of the preformatted text block. The value of this attribute is the number of characters that should form a line of text, however it should also be noted that this is an attribute that is in practice not supported by most browsers.

Event handlers

The following event handlers are defined for this element:

Basic example

<pre>This
    is
  preformatted
        text.</pre>

The above code will display something like:

This
    is
  preformatted
        text.

Compatibility

Description: Support of preformatted text and attributes in various browsers
Test Internet Explorer 6+ Netscape 4 Mozilla and Netscape 6+ Opera 6+ MSN TV (WebTV) Konqeuror 3.0+
Basic element support  Yes  Yes  Yes  Yes  Yes  Yes 
Attribute: class  Yes  Yes  Yes  Yes  Yes  Yes 
Attribute: dir  Yes  No  Yes  No  No  No 
Attribute: id  Yes  Yes  Yes  Yes  Yes  Yes 
Attribute: lang  Yes  Yes  No  No  No  No 
Attribute: style  Yes  Yes  Yes  Yes  Yes  Yes 
Attribute: title  Yes  No  Yes  Yes  No  Yes 
Attribute: width  No  No  Yes  No  No  No 

Key:
The browser icons are explained in the below list:
Internet Explorer 6+ = Microsoft Internet Explorer 6+
Netscape 4 = Netscape Communicator 4
Mozilla and Netscape 6+ = Mozilla and Netscape Navigator 6+
Opera 7+ = Opera 7+
MSN TV (WebTV) = MSN TV (aka. WebTV)
Konqeuror 3.0+ = Konqueror 3.0+