Special tags to display html code on the page

sanHTM

If anyone knows what tags should be used to display HTML tags with the text we write - in another word, the tags that can display other HTML tags in a browser?

Thank you in advance.

Regards

SanHTM

Robin_reala

6:03 pm on Feb 1, 2007 (gmt 0)

Welcome to WebmasterWorld, sanHTM!

This will actually be a combination of two elements and some escaping. To start off with you'd want to set up the following code:

<pre><code>YOUR CODE HERE</code></pre>

This says that you want you whitespace to remain as written (<pre>) - important for computer code. The <code> element is a semantic definition that states that the text inside it is computer code.

If you do just this you'll find that your HTML is still rendered by the browser though. The fix for this is to escape the angle brackets that encompass your tags. This is pretty simple: replace a < symbol with &lt; and a > symbol with &gt;. Your code will then show up inside your page.

[edited by: Robin_reala at 6:04 pm (utc) on Feb. 1, 2007]

sanHTM

8:19 pm on Feb 1, 2007 (gmt 0)

Thank you for your prompt reply. Your codes won't work as:

<pre></pre> - is used just for recognising the white space <code></code> - is used just to identify these are the starts of computer codes, etc.

sanHTM

Do you know any other similar HTML tags to the above which can display HTML tags in the browser?

appreciate your great help.

Cheers

encyclo

9:05 pm on Feb 1, 2007 (gmt 0)

Like I said,

XMP

is obscure. :) There are no other HTML elements which function in the same way, if

XMP

won't do it, then you have to use the entities or the

textarea

as mentioned above.

sanHTM

9:20 pm on Feb 1, 2007 (gmt 0)

I think there must be a new HTML tag that replaces <xmp> for new versions of Browser?

Or can we use the server-scripting languages to do that without writing entity names?

Cheers

eelixduppy

9:21 pm on Feb 1, 2007 (gmt 0)

Or can we use the server-scripting languages to do that without writing entity names?

Server-side technologies are a possibility. For example, PHP has its htmlentities [us2.php.net] function.

encyclo

9:23 pm on Feb 1, 2007 (gmt 0)

there must be a new HTML tag

There maybe should be one, but there isn't.

Of course if you have access to a server-side scripting language you can use it to escape the HTML and convert it to the entities, as mentioned above.

sanHTM

9:29 pm on Feb 1, 2007 (gmt 0)

Thank you again for your great help. I have been designing a web pages for a while, but never thought about it. Recently someone asked me if we can display HTML tags in browser, I said No as I was thinking of using server-script languages instead of using HTML tags directly. It was a stupid answer. Never mind, it has been done.

If you have any other options that could be easier than php scripting?

Cheers

sanHTM

8:35 am on Feb 2, 2007 (gmt 0)

Of course if you have access to a server-side scripting language you can use it to escape the HTML and convert it to the entities, as mentioned above.

If there any VB codes used inline along HTML to display HTML tags in the browser?

phranque

11:46 pm on Feb 2, 2007 (gmt 0)

don't forget to also replace '&' with '&amp;'.

then if you have named or numeric entities in your html you will see them as such rather than as rendered by the browser. it will also prevent "accidental" entities, for example the following "pure text" string: drums&sticks;guitar&amp;piano;...