Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display HTML tags as text

Tags:

html

How can I display HTML tags in a .html page without having my browser try to execute whatever is in the tag.

like image 751
MonuMan5 Avatar asked Dec 20 '11 05:12

MonuMan5


People also ask

How do I view HTML code?

You can include code examples in your HTML by using the <code> tag. This automatically uses a monospaced font and also semantically labels our code as what it is.

How do I display HTML tags as plain text in jquery?

Just write the HTML correctly in the first place. If you want to render a < character then put &lt; in the HTML (and so on). Don't try to escape the HTML with JavaScript after the browser has already parsed it.


1 Answers

You must use use the escaped version. For example < becomes &lt; (no quotes) and & becomes &amp;.

You should be able to find a full list of transformations.

An example snippet:

&lt;a href="http://google.com"&gt;Google&lt;/a&gt;

is the escaped version of:

<a href="http://google.com">Google</a>

Edit:

The standard's list of entities: http://www.w3.org/TR/html4/sgml/entities.html

A Wikipedia artcile on it: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

like image 187
Corbin Avatar answered Sep 20 '22 11:09

Corbin