<pre>
Example
<pre>
<div class="box">
<p>Hi</p>
</div>
</pre><pre><code><div class="box">
<p>Hi</p>
</div></code></pre>Escaped tags inside <pre><code> show as text instead of being parsed and rendered.
Common mistakes
- Pasting raw HTML into
<pre>, so tags render instead of showing as text. - Indenting the content to match the source, which adds spaces to the output.
Key points
- Code blocks use
<pre><code>, with<code>inside<pre>. <,>and&inside the block are escaped as<,>and&.- Long lines scroll with
overflow-x: autoinstead of breaking the layout.
Interview questions
Why is the first line break in pre ignored?
Browsers drop one newline right after <pre>, but indentation and other line breaks inside are kept as written.
How do I wrap long lines in pre?
Use CSS white-space: pre-wrap, or keep the lines and add overflow-x: auto for scrolling.