Definition and usage
The Pre element defines preformatted text. The text enclosed in the PRE element usually preserves spaces and line breaks. The text renders in a fixed-pitch font.
Pre-formatted text can be defined using the pre element. All blank intervals and line breaks of text in the PRE element are retained.
Differences between HTML and XHTML
The "width" attribute of the PRE element was deprecated in HTML 4.01.
The "width" attribute of the PRE element is not supported in html4.01.
The "width" attribute of the PRE element is not supported in XHTML 1.0 strict DTD.
The strict-type DTD of xhtml1.0 no longer supports the "width" attribute in the PRE element.
Notes about <PRE>
It is worth noting that while <XMP> is deprecated, the <PRE> tag does not perform all of the functions of <XMP>:
When <XMP> is not recommended, <PRE> has no value. <PRE> cannot provide the same functions as <XMP>:
<PRE> <B> Hello </B> </PRE> is displayedHello
<XMP> <B> Hello </B> </XMP>: <B> Hello </B>
Instance
Code |
Output result |
<PRE> This text is In a fixed-pitch Font, and it preserves Both spaces and Line breaks </PRE> |
This text is In a fixed-pitch Font, and it preserves Both spaces and Line breaks
|
Optional attributes
DTDIndicates in which DTD the attribute is allowed. S = strict, t = transitional, and f = frameset.
The DTD column in the following Table specifies the supported DTD attributes. S = strict (accurate), t = transitional (traditional), F = frameset (framework)
Attribute |
Value |
Description |
DTD |
Width |
Number |
Defines the maximum number of characters per line (usually 40, 80, or 132) Defines the maximum number of characters acceptable to each row of pre (generally 40, 80 or 132) |
TF |
Standard attributes
ID, class, title, style, Dir, Lang, XML: Lang, XML: Space |
For a full description, go to standard attributes.
View complete attributes
Event attributes
Onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup |
For a full description, go to event attributes.
View complete attributes
Try and demo
Preformatted text
How to control line breaks and spaces with the PRE Tag.
Use pre labels to control line feed and white space