The PRE Formatted Text Element

The <pre> element of HTML is used to insert any preformatted text in the HTML Document. This imples that the spaces, tabs, return keys, and other formatting characters are preserved and displayed as they appear in the content of the <pre> element. On most of the browsers, the contents of the <pre> are displayed using a monospace font like courier.

Syntax:
<pre property=”value” property=”value”>
contents of the pre formatted element
</pre>

Valid Properties:
1. width The width attribute is used to set the width of the pre-formatted region. The value of this attribute should be the largest / maximum number of characters that appear on a single line of the contents of the <pre> element. However, in prectice, this property is available only under the Transitional HTML versions.
2. xml:space This property is included in the XHTML 1.0 specification and is used to set whether spaces need to be preserved within the <pre>…</pre> tags or whether the default white space handling should be employed. In practice, this attribute is not used. The only allowe value for this property is “preserve”.

Other properties for the <pre> element include the following common properties – class, dir, id, lang, style, title.

Refer to  Common Properties page for details of these properties.

Example:
<pre>
1
121
12321
1234321
12321
121
1
</pre>

Notes:
1. Under the Transitional HTML and XHTML versions, the use of <applet>, <basefont>, <big>, <font>, <img>, <object>, <small>, <sub> and <sup> HTML elements is denied within the <pre> element.
2. Under the Strict HTML and XHTML versions, only the <big>, <img>, <object>, <small>, <sub> and <sup> HTML elements are denied usage within the <pre> element.
3. Strict HTML and XHTML do not support the width attribute.
4. HTML 2.0 and HTML 3.2 support only the width property for the <pre> element.
5. The most essential point to note is that though <pre> element is not supposed to contain many HTML elements, the browsers do not obey this rule and will render almost all of the HTML elements even if they are enclosed within the <pre> element.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.