The HTML <pre> element 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.
| Content categories | Flow content, palpable content. |
|---|---|
| Permitted content | Phrasing content. |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts flow content. |
| Permitted ARIA roles | Any |
| DOM interface | HTMLPreElement |
Attributes
This element only includes the global attributes.
cols- Contains the preferred count of characters that a line should have. It was a non-standard synonym of
width. To achieve such an effect, use CSSwidthinstead. width- Contains the preferred count of characters that a line should have. Though technically still implemented, this attribute has no visual effect; to achieve such an effect, use CSS
widthinstead. wrap- Is a hint indicating how the overflow must happen. In modern browser this hint is ignored and no visual effect results in its present; to achieve such an effect, use CSS
white-spaceinstead.
Examples
<!-- Some example CSS code -->
<pre>
body {
color:red;
}
</pre>
Result
body {
color:red;
}
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of '<pre>' in that specification. |
Living Standard | No significant change from HTML5 |
| HTML5 The definition of '<pre>' in that specification. |
Recommendation | No significant change from HTML 4.01 Specification |
| HTML 4.01 Specification The definition of '<pre>' in that specification. |
Recommendation | Deprecated the cols attribute |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic Support | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
cols | No | No | 1 — 29 | No | No | No |
width | (Yes)1 | (Yes)1 | 12 | (Yes)1 | (Yes)1 | (Yes)1 |
wrap | ? | No | 1 | ? | ? | ? |
| Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
|---|---|---|---|---|---|---|---|
| Basic Support | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
cols | No | No | No | 1 — 29 | No | No | No |
width | (Yes)1 | (Yes)1 | (Yes)1 | 12 | (Yes)1 | (Yes)1 | (Yes)1 |
wrap | ? | ? | No | 1 | ? | ? | ? |
1. Specifying the width attribute has no layout effect.
2. Since Firefox 29, specifying the width attribute has no layout effect.
See also
- CSS:
white-space,word-break

