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

I need to include some codes in my html document

I tried the <pre> , but that didn't help.

How do I get this code in a document as text?

thanks

+7
source share
6 answers

The short answer.

Encode your code using the HTML Encoder online code and then enter it inside pre

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

Long answer.

The above will help you show your code. If you want to highlight your code correctly, try something like SyntaxHighlighter

Link: How to use SyntaxHighlighter.

+7
source

You must use the html entity . Example:

 <div> Some Stuff </div> 

it should be

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

and it will appear as the first

+9
source

You can use the <pre> . Each time you insert any texts in the <pre> , it is not processed as an html document. One caveat though, if you try to put an opening HTML tag inside a preliminary tag, you should do it like this:

 <pre> &lt;TEST> TEST!! &lt;/TEST> </pre> 
+4
source

You can use a combination of <pre> and <code> tags. The <pre> saves formatting, and the <code> is displayed in a monospaced font. Wrap the <code> tag in the <pre> and insert any block of code in the body of the <code> elements. This will be output as follows:

<pre> <code> function(){ var myVar = "This is code"; return myVar; } </code> </pre>

0
source

Some people can crucify me without escaping my code. But it worked for me.

CSS

 .tag:before{ content: '<' } .tag:after{ content: '>' } 

HTML

 <pre> <span class="tag">tag</span> </pre> <!--Instead of having to escaping all the character--> &lt;tag&gt; &lt;&#47;tag&gt; <!--Kinda interested to see why this is bad. I understand that not escaping code can be dangerous b/c of SQL injections and all sort of BS but why is this not a viable option--> 
0
source

Using encode

Example:

 <br> -> encoded -> &lt;br&gt; use &lt;br&gt; in your text 

Same answer as Ibu, but maybe you need a quick way to encode your tags.

0
source

All Articles