Display HTML code in HTML

The tried and true method for HTML:

Replace the & character with &
Replace the < character with <
Replace the > character with >
Optionally surround your HTML sample with <pre> and/or <code> tags

Best way:

<xmp> // your codes .. </xmp>

Old samples:

Sample 1:

<pre> This text has been formatted using the HTML pre tag. The brower should display all white space as it was entered. </pre>

Sample 2:

<pre> <code> My pre-formatted code here. </code> </pre>

Sample 3:

(If you are actually "quoting" a block of code, then the markup would be)
<blockquote> <pre> <code> My pre-formatted "quoted" code here. </code> </pre> </blockquote>

nice CSS sample:

pre{ font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif; margin-bottom: 10px; overflow: auto; width: auto; padding: 5px; background-color: #eee; width: 650px!ie7; padding-bottom: 20px!ie7; max-height: 600px; }

Deprecated, but works in FF3 and IE8.

<xm>p <b>bold</b><ul><li>list item</li></ul> </xmp>

Recommended:

<pre><code> code here, escape it yourself. </code></pre>

Comments