tags:

views:

54

answers:

4

I want to display code characters on an html page. But no matter what i try it always renders html characters. Pre or code doesnt work. How can I do this?

+2  A: 

You need to use character references instead of the plain characters themselves:

<code>&lt;HTML&gt;</code>

The elements code and pre are just to mark the content as code or preformated.

Gumbo
+2  A: 

By escaping them.
&amp; will print &
&lt; will print >

You didn't mention what you're using to generate the html, if you're manually editing, some editors have options to escape a selection. If you're using a language, look for some function that escapes html special characters. (google for how to escape html in language-name-here)

Prody
A: 

The <xmp> tag doesn't require the contents to be escaped.

eg:

<xmp>
    <p>Blah &nbsp;</p>
</xmp>

...will look like this on your screen:

    <p>Blah &nbsp;</p>
nickf
A: 

Look for an HtmlEncode function in your language.

string s = HtmlEncode(myInput); response.write(s)

or similar

No Refunds No Returns