Steven Steven - 1 year ago 176
HTML Question

Display HTML code in HTML

Is there a way to show HTML code-snippets on a webpage without needing to replace each < with

and > with

In other words, is there some tag which simply says "Don't render HTML until you hit the closing tag"?

Answer Source

In HTML proper, there’s no way short of escaping the characters. However, in properly declared XHTML (which is XML, and needs to be declared to the browser as such; in particular it’s not enough to just put in a DOCTYPE), you can use a CDATA section:

<![CDATA[Your <code> here]]>

But this only works in XML, not in HTML.

In HTML, the only solution guaranteed to work everywhere is to escape the code (< and & as &lt; and &amp;, respectively) manually.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download