HTML - <pre>
The HTML <pre>
element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional ("monospace") font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.
Examples
Example1
<!-- Some example CSS code --> <pre> body { color:red; } </pre>
Result
body { color:red; }
Description
The HTML <pre>
element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional ("monospace") font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.
Note: you will need to escape any contained '<
' characters as '<
' to make sure enclosed code is not interpreted as markup.
Content categories | Flow content, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parent elements | Any element that accepts flow content. |
DOM interface | HTMLPreElement |
Browser Compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | (Yes) | (Yes) | (Yes) |
width |
(Yes)[1] | 1.0 (1.7 or earlier) 29.0 (29.0)[1] |
(Yes)[1] | (Yes)[1] | (Yes)[1] |
cols |
No support | 1.0 (1.7 or earlier) No support 29.0 (29.0) |
No support | No support | No support |
wrap |
? | 1.0 (1.7 or earlier) | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | 1.0 (1.0) | (Yes) | (Yes) | (Yes) |
width |
? | 1.0 (1.0)29.0 (29.0)[1] | ? | ? | ? |
cols |
No support | 1.0 (1.0) | No support | No support | No support |
wrap |
? | 1.0 (1.0) | ? | ? | ? |
[1] Specifying the width
attribute has no layout effect.
See Also
- CSS:
white-space
,word-break
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of '<pre>' in that specification. |
Living Standard | No significant change from WHATWG HTML Living Standard |
HTML5 The definition of '<pre>' in that specification. |
Recommendation | No significant change from HTML 4.01 Specification |
HTML 4.01 Specification The definition of '<dl>' in that specification. |
Recommendation | Deprecated the cols attribute |
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/pre