18

I have some HTML script that I would like to make it display in a web page like the code option here:

<a href="#">test</a>

How can I do that?

2 Answers 2

24

You need to HTML-escape your text, as you can easily tell if you look at the HTML source of this very page:

<div class="post-text">
    <p>I have some HTML that I would like to make it appear like the code option here</p>

    <pre><code>&lt;a href="#"&gt;test&lt;/a&gt;
    </code></pre>

    <p>How can I do it?</p>
</div>            
Sign up to request clarification or add additional context in comments.

Comments

11

You'll need to encode the angle brackets etc in order to show this on the page.

You can do this manually in html as:

&lt;a href="#"&gt;test&lt;/a&gt;

Where:

&lt; = <

&gt; = >

For other characters here's a table of character codes: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

2 Comments

"HTML codes" and "HTML number" must be the most ignorant way of labelling the table -- what a terrible website. Even Wikipedia makes a better reference...
Thanks Kerrek. I've replaced the link with this better reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.