Forum Moderators: open
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 < and a > symbol with >. Your code will then show up inside your page.
[edited by: Robin_reala at 6:04 pm (utc) on Feb. 1, 2007]
Here is an example of Robin_reala's suggestion...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
#container {
width:600px;
height:200px;
border:1px solid #000;
font-family:verdana,arial,sans-serif;
font-size:14px;
overflow:auto;
}
</style></head>
<body><div id="container">
<pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body><div></div>
</body>
</html></pre>
</div>
</body>
</html>
<p>
To create a paragraph, surround your paragraph with <p> and </p>.
</p>
This would then output this when viewed in a browser:
To create a paragraph, surround your paragraph with <p> and </p>.
You can find the entire list of entities in the HTML spec. [w3.org]
[edited by: encyclo at 8:38 pm (utc) on Feb. 1, 2007]
[edit reason] spliced from duplicate thread [/edit]
<textarea>
<html><body></body></html>
</textarea>
Of course you can style the textarea however you like to display the code.
You can try using
XMP, but it's so old you may not get decent browser support: [b]<xmp>[/b] ... your HTML here ... [b]</xmp>[/b] I believe Firefox (Mozilla) still recognizes the
XMP element, not sure for IE. XMP was included in HTML 2.0 but removed in subsequent versions. W3C reference for
(HTML 2.0) [w3.org]
XMP
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.
If you have any other options that could be easier than php scripting?
Cheers
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&piano;...
(which the browser would render as: drums&sticks;guitar&piano;...)