<pre> (Preformatted Text)
This element is used to indicate that the enclosed text is preformatted, meaning that spaces, returns, tabs, and other formatting characters are preserved. Browsers will, however, acknowledge most HTML elements that are found within a <pre> tag. Preformatted text generally will be rendered by the browsers in a monospaced font.
dir="ltr | rtl"
id="unique alphanumeric value"
width="number" (transitional only)
Attributes Defined by Internet Explorer
contenteditable="false | true | inherit"(5.5)
disabled="false | true"(5.5)
hidefocus="true | false"(5.5)
wrap="soft | hard | off"(4)
Standard Event Attributes
onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmouseomove, onmouseout, onmouseover, onmouseup
Events Defined by Internet Explorer
onactivate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onblur, oncontextmenu, oncontrolselect, oncopy, oncut, ondeactivate, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onfocus, onfocusin, onfocusout, onhelp, onlosecapture, onmouseenter, onmouseleave, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresize, onresizeend, onresizestart, onselectstart, ontimeerror
Element Specific Attributes
- This attribute should be set to the width of the preformatted region. The value of the attribute should be the number of characters to display. In practice, this attribute is not supported and is dropped under the strict HTML 4.01 specification.
- In some versions of Microsoft browsers, this attribute controls word wrap behavior within a <pre> tag. The default value of off for the attribute forces the element not to wrap text, so the author must manually enter line breaks. Values of hard or soft cause word wrap and set different types of line breaks in the wrapped text. Given the nature of the pre element, the value of this attribute is limited.
- This attribute is included from XHTML 1.0 and is used to set whether spaces need to be preserved within the element or whether the default white space handling should be employed. It is curious that an element defined to override traditional white space rules would allow such an attribute, and in practice this attribute is not used by developers.
Within PREFORMATTED text A L L formatting IS PRESERVED NO m a t t e r how wild it is. Remember that some <b>HTML</b> markup is allowed within the <PRE> element.
HTML 2, 3.2, 4, 4.01
XHTML 1.0, 1.1, Basic
Internet Explorer 2, 3, 4, 5, 5.5, 6
Netscape 1, 2, 3, 4, 4.5 4.8, 6, 7
Opera 4 7
The HTML 4.01 transitional specification states that the applet, basefont, big, font, img, object, small, sub, and sup elements should not be used within the <pre> tag. The strict HTML 4 specification states that only the <big>, <img>, <object>, <small>, <sub>, and <sup> tags should not be used within the <pre> tag. The other excluded elements are missing, as they are deprecated from the strict specification. Although these attributes should not be used, it appears that the two most popular browsers will render them anyway.
The strict HTML and XHTML specifications drop support for the width attribute, which was not well-supported anyway.
The HTML 2.0 and 3.2 specifications support only the width attribute for <pre>.