PDA

View Full Version : How to show HTML code



narlyjustyn
03 Jun 2008, 02:23 AM
I would like to display HTML code in a text box for people to copy and paste.

I've tried several methods, including <pre><code>; the "&amp," etc. language; and <textarea>

I've had the best luck with <textarea>, but viewers copying and pasting only works in Mozilla--not Internet Explorer.

Please help! :)

Wickham
03 Jun 2008, 04:02 AM
You need to use special character codes as shown here:-
http://www.tedmontgomery.com/tutorial/HTMLchrc.html
definitely for the < at the beginning of every tag; some people say every > closing tag but I've found it unnecessary.

so instead of <div>........</div> in your code you type &lt;div>.........&lt;/div> and it shows in the web page as <div>........</div> instead of being operated as code by the browser and viewers can copy/paste it.

Remember to do it at the beginning of every tag.

There is an online code converter here if you have a lot to convert:-
http://www.tutorialtastic.co.uk/converter.php

If you put <code>.............</code> tags around your converted code it will dispaly as a different font-family to show that it is code. You can style the code tag if you want:-

code { font-family: monospace; color: red; }