Consider TextArea
People finding this via Google and looking for a better way to manage the display of their snippets should also consider <textarea>
which gives a lot of control over width/height, scrolling etc. Noting that @vsync mentioned the deprecated tag <xmp>
, I find <textarea readonly>
is an excellent substitute for displaying HTML without the need to escape anything inside it (except where </textarea>
might appear within).
For example, to display a single line with controlled line wrapping, consider <textarea rows=1 cols=100 readonly>
your html or etc with any characters including tabs and CrLf's </textarea>
.
<textarea rows=5 cols=100 readonly>Example text with Newlines,_x000D_
tabs & space,_x000D_
html tags etc <b>displayed</b>._x000D_
However, note that & still acts as an escape char.._x000D_
Eg: <u>(text)</u>_x000D_
</textarea>
_x000D_
To compare all...
<h2>Compared: TEXTAREA, XMP, PRE, SAMP, CODE</h2>_x000D_
<p>Note that CSS can be used to override default fixed space fonts in each or all these.</p>_x000D_
_x000D_
_x000D_
<textarea rows=5 cols=100 readonly>TEXTAREA: Example text with Newlines,_x000D_
tabs & space,_x000D_
html tags etc <b>displayed natively</b>._x000D_
However, note that & still acts as an escape char.._x000D_
Eg: <u>(text)</u></textarea>_x000D_
_x000D_
<xmp>XMP: Example text with Newlines,_x000D_
tabs & space,_x000D_
html tags etc <b>displayed natively</b>._x000D_
However, note that & (&) will not act as an escape char.._x000D_
Eg: <u>(text)</u>_x000D_
</xmp>_x000D_
_x000D_
<pre>PRE: Example text with Newlines,_x000D_
tabs & space,_x000D_
html tags etc <b>are interpreted, not displayed</b>._x000D_
However, note that & still acts as an escape char.._x000D_
Eg: <u>(text)</u>_x000D_
</pre>_x000D_
_x000D_
<samp>SAMP: Example text with Newlines,_x000D_
tabs & space,_x000D_
html tags etc <b>are interpreted, not displayed</b>._x000D_
However, note that & still acts as an escape char.._x000D_
Eg: <u>(text)</u>_x000D_
</samp>_x000D_
_x000D_
<code>CODE: Example text with Newlines,_x000D_
tabs & space,_x000D_
html tags etc <b>are interpreted, not displayed</b>._x000D_
However, note that & still acts as an escape char.._x000D_
Eg: <u>(text)</u>_x000D_
</code>
_x000D_