Little Web Hut

HTML 4.01 and XHTML 1.0 Reference: <pre> Tag

HTML <pre> Tag - Preformatted Text
Syntax This element uses separate opening and closing tags.
<pre>...</pre>
Usage The <pre> tag is used to specify that the text, located between the opening and closing <pre> tags, is preformatted. The text should be displayed without altering whitespace characters. For example, multiple spaces and line breaks should be preserved. A mono spaced font, like courier, is also used.

HTML & XHTML <pre> tag example.
<pre>
Month     Days
______________
January   31
February  28 or 29
March     31
April     30
</pre>
Test It HTML StyleTest It XHTML Style

Content Model The <pre> element can contain the following tags, and Text, between its opening and closing tags.Notes:
1. The <pre> element can contain the <iframe> tag when using HTML DTD Transitional and Frameset documents but not Strict documents. The <pre> element cannot contain the <iframe> tag when using XHTML documents.
2. The <pre> element cannot contain the <map> tag when using XHTML DTD Transitional or Frameset documents.
3. The <pre> element can contain the <big>, <small>, <sub>, and <sup> tags when using XHTML DTD Strict documents. However, these four tags are possibly only allowed as the result of an error in the XHTML version 1.0 Strict DTD. Therefore, it would be advisable to avoid using these four tags inside of the <pre> element.
4. Red tags have been deprecated and are allowed in DTD Transitional and Frameset documents but not Strict documents.

Red attributes have been deprecated
<pre> Tag Attribute Summary
Required Tag Specific Core Focus Events Language
  width xml:space1 id class style title   onclick ondblclick onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup dir lang xml:lang1
Notes: 1. XHTML only.

Red attributes have been deprecated
<pre> Tag Attributes
Attribute Description
widthThe width attribute specifies the number of characters per line.

<pre> tag example using the width attribute.
<pre width="10">This sample uses the preformatted text tag</pre>


Note: This attribute has been deprecated.
xml:spaceThe xml:space attribute is used to specify that whitespace should be preserved.

<pre> tag example using the xml:space attribute.
<pre xml:space="preserve">
This sample uses the preformatted text tag</pre>


Note: XHTML only.
idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example
classThe class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. See class Example
styleThe style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. See style Example
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example
onclickThe onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. See onclick Example
ondblclickThe ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. See ondblclick Example
onkeydownThe onkeydown attribute specifies a script to be run when a key is pressed down. See onkeydown Example
onkeypressThe onkeypress attribute specifies a script to be run when a key is pressed and released. See onkeypress Example
onkeyupThe onkeyup attribute specifies a script to be run when a key is released. See onkeyup Example
onmousedownThe onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. See onmousedown Example
onmousemoveThe onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. See onmousemove Example
onmouseoutThe onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it. See onmouseout Example
onmouseoverThe onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. See onmouseover Example
onmouseupThe onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object. See onmouseup Example
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example

Note: XHTML only.

HTML <pre> Tag Examples
Test It HTML StyleTest It HTML Style<pre> tag example.