Is there a way to show HTML code-snippets on a webpage without needing to replace each < with
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 (
&, respectively) manually.