<pre>
The <pre> element represents preformatted text. Whitespace, line breaks, and spacing in the source code are preserved exactly as written. Text is typically displayed in a monospace font.
This page was last updated on 2025-11-27
Syntax
<pre>preformatted text here</pre>
Attributes
- class - CSS class name
- id - Unique identifier
- style - Inline CSS styles
- title - Advisory information
Examples
Code sample:
<pre><code>
function greet(name) {
return "Hello, " + name;
}
</code></pre>
ASCII art:
<pre>
/\___/\
( o o )
( =^= )
( )
</pre>
Data table:
<pre>
Name Age City
Alice 25 Dublin
Bob 30 Cork
</pre>
When to Use
Use <pre> when spacing and formatting are significant to the meaning of the content. This includes computer code, ASCII art, poetry with specific formatting, or data where column alignment matters.
For code samples, wrap the text in both <pre> and <code> elements. The <pre> preserves formatting while <code> indicates the content is computer code. Remember that HTML entities inside <pre> are still interpreted, so use < for < and > for > when displaying HTML code.
Related Elements
- <code> - Computer code text
- <p> - Paragraph (collapses whitespace)
- <blockquote> - Block quotation