How can I show HTML code on a web page?

They have: 99 posts

Joined: Feb 2008

Is there a way where I can show the html tags e.g. on a web page without it being rendered as code?

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

yep, there is. In stead of typing
'<tag>', you type '& #60;tag& #62;', without the spaces

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

actually, use the the following:

&lt; (less than, the left angle bracket)
&gt; (greater than, the right angle bracket)

-Greg

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Greg K wrote: actually, use the the following:

&lt; (less than, the left angle bracket)
&gt; (greater than, the right angle bracket)

-Greg

I remember using the decimals in stead of the entity reference has better chances (as in 100% compared to 99% or so) to work.
I can't remember where I've read that of course Plain, anyone?

Shakespeare: onclick || !(onclick)

He has: 629 posts

Joined: May 2007

To the above, add "&amp;" to replace any ampersand (&).

He has: 629 posts

Joined: May 2007

Jack Michaelson raises an interesting point.

All "latin" encodings (ISO-8859-?), as well as UTF-8 share the same characters in the first 127 places, so no entities are needed to display them when using the usual 8-bit editors most of us employ. For displaying European accented characters in the 192-255 character range, the named entities are preferred and have worked since HTML 2.0. Entities in the range 160-191 are newer, and it is in respect of these that you may have read the caution, as the numbered version always works.

Eight bit encoding is limited to 256 characters (0-255), but Unicode supports a far bigger range than this, which is why you see entities like &8220; for example. I prefer to use an editor and an FTP client that supports UTF-8. Oh, and you need your server to send the appropriate header. This way you can enter every character "natively" which makes text far easier to read, especially if, like me, you like typographic niceties like "curly quotes." But that's just me.

To get back to the original question - &lt; &gt; &quot; and &amp; are part of both the HTML and XML languages, so are preferred for marking up code.

Sorry about the long post, but character encoding seems to be one of the least understood aspects of making web pages. Plain

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

They have: 99 posts

Joined: Feb 2008

Thanks guys, would I be better using a text box or is that a no no?

He has: 629 posts

Joined: May 2007

If you mean a textarea, well, the same issues apply. You still need to use &lt; etc. even when displaying in a textarea.

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Use a textarea when you want the users to make edits to the code. If that's not necessary I'd suggest just put it in a block element.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.