The <pre> element represents preformatted text shown exactly as written in the HTML file. Spaces, tabs, and line breaks stay visible. Browsers typically use a monospace font.
For code listings, nest <code> inside <pre>. Use <samp> for sample output and <kbd> for typed input when that meaning fits. Content inside <pre> is still HTML — escape special characters when needed.
Baseline · Widely available.
Not deprecated. Stable across browsers since about July 2015 (and much earlier in practice).
A leading newline right after the opening <pre> tag is stripped by the HTML parser (not in XHTML). Put the first line of text on the same line as <pre> when every blank line matters.
Syntax
HTML Syntax
syntax.html
<pre>text…</pre>
Both start and end tags are required. Content is phrasing content only (no nested blocks like <div> or <p>). Escape < and & when those characters should appear as text.
Reference
Attributes
Modern <pre> has no useful element-specific attributes — only globals. Two legacy attributes remain for reference:
Most pre bugs are missing escapes, wrong nesting, or treating character art as plain text for everyone.
escape
Escape < and & in source
Unescaped markup can create real elements or break the page. Prefer entities inside HTML source, especially for HTML samples.
newline
First newline after <pre> is stripped
The HTML parser removes the first leading newline after the opening tag. Start content on the same line when that blank line matters.
content
Only phrasing content inside
Do not nest block elements. Use <code>, <samp>, <kbd>, and similar phrasing tags when needed.
a11y
Describe ASCII diagrams
Screen readers may read character art letter by letter. Pair with aria-label (and often a caption) so the meaning is clear.
layout
Long lines can overflow
Default white-space: pre does not wrap. Add CSS such as overflow-x: auto or adjust white-space for narrow screens.
Compatibility
Browser Support
The <pre> element is core HTML flow content in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<pre>
Widely available since about July 2015 (and long before). Chrome, Firefox, Safari, Edge, and Opera all support preformatted text with default monospace styling.
98%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Supported
<pre>Widely supported
Bottom line: Safe to use everywhere for preformatted text. Nest code for listings, escape special HTML characters, and describe ASCII art for accessibility.
Remember
Key Takeaways
Role:<pre> keeps spaces and line breaks; default look is monospace.
Code: use <pre><code>…</code></pre> for multi-line samples.
Escape: write < and & in HTML source when needed.
Legacy: skip deprecated width / wrap; style with CSS instead.
One line: use <pre> when whitespace matters; nest <code> for code blocks.
You can restyle with CSS (background, padding, overflow). User font preferences may override your font-family choice.
Frequently Asked Questions
The pre element shows preformatted text: spaces and line breaks are kept as written in the HTML source. Browsers usually render it in a monospace font.
Yes for code blocks. Nest code inside pre: pre keeps layout; code marks the text as computer code. Alone, code is for short inline phrases.
Yes when those characters would start real HTML tags. Write < and usually & for & so the browser shows them as text.
No modern element-specific attributes. Use global attributes. The old width and wrap attributes are deprecated and have no useful visual effect — use CSS instead.
If one or more newlines come right after the opening pre tag, the HTML parser strips the first newline. Put content on the same line as <pre> or accept that strip.
No. It is Baseline and widely available. Prefer it for preserved whitespace; obsolete peers like listing and plaintext are not for new pages.