Skip to content

13. pre Tag

The <pre> (preformatted) element preserves whitespace, line breaks, and formatting exactly as written in the HTML source. It’s commonly used for code blocks, ASCII art, or any content where exact formatting is important. The pre element also uses a monospace font by default.

<pre>
This text
preserves spaces
and line breaks.
</pre>

Displaying code:

<pre>
function hello() {
console.log("Hello, World!");
}
</pre>
<pre>
/\_/\
( o.o )
> ^ <
</pre>

Preserving formatting:

<pre>
Name: John Doe
Email: john@example.com
Phone: 123-456-7890
</pre>

Customize appearance:

<pre>
Code here
</pre>
<style>
pre {
background-color: #f4f4f4;
padding: 1em;
border-radius: 4px;
overflow-x: auto;
}
</style>

For code, consider using <code> with <pre>:

<pre><code>
function example() {
return "Hello";
}
</code></pre>