How to make html ignore code that is part of text?

You have to use html entities. Example:

<div>
   Some Stuff
</div>

should be

&lt;div&gt;
   Some Stuff
&lt;/div&gt;

and it will render as the first one


Use the xmp tag. It is easier and quicker than using an HTML encoder. Example:

<h1>This is a heading.</h1>
<p>This is a pharagraph</p>
<xmp>
<h1>This is a heading.</h1>
<p>This is a pharagraph</p>
</xmp>

You can use <pre> tag. Each time you insert any texts within the <pre> tag it wont get parsed as html document. One caveat though, if you try to put an opening HTML tag inside the pre tag, you have to do it like this:

<pre>
     &lt;TEST>
            TEST!!
     &lt;/TEST>
</pre>

Short Answer.

Encode your code using an online HTML Encoder and then put it inside pre

<pre>
    <%--your encoded code goes here--%>
</pre>

Long Answer.

The above will only help you to show your code. If you want proper highlighting for your code, Try something like SyntaxHighlighter

Link: How to use SyntaxHighlighter.

Tags:

Html