How can I display HTML tags in a .html
page without having my browser try to execute whatever is in the tag.
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.
Just write the HTML correctly in the first place. If you want to render a < character then put < in the HTML (and so on). Don't try to escape the HTML with JavaScript after the browser has already parsed it.
You must use use the escaped version. For example <
becomes <
(no quotes) and &
becomes &
.
You should be able to find a full list of transformations.
An example snippet:
<a href="http://google.com">Google</a>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With