Display HTML snippets in HTML

Steven picture Steven · May 12, 2010 · Viewed 456.4k times · Source

How can I show HTML snippets on a webpage without needing to replace each < with &lt; and > with &gt;?

In other words, is there a tag for don't render HTML until you hit the closing tag?

Answer

Dolph picture Dolph · May 12, 2010

The tried and true method for HTML:

  1. Replace the & character with &amp;
  2. Replace the < character with &lt;
  3. Replace the > character with &gt;
  4. Optionally surround your HTML sample with <pre> and/or <code> tags.