I am building a simple html tutorial for my university . But I am not able to put the examples within the html file ! I tried <code></code> but it did not worked ! I searched google but no help from there .
1 Answer
You need to HTML escape any HTML special characters.
To conserve the indentation, you should wrap it in <pre> tags.
To format it as code visually, you should also wrap it in <code> tags.
The results looks like this:
<pre><code>
<p>
This is an example of
<strong>HTML</strong>.
</p>
</code></pre>
This is rendered as:
<p>
This is an example of
<strong>HTML</strong>.
</p>
6 Comments
mal-wan
This is the correct way. @Suraj, there are tools on the internet to help you quickly escape special characters such as this one: felgall.com/htmlt47.htm
Jared Farrish
What is the benefit of using
CODE like that?Suraj Hazarika
Thank you very much mwan100....I was wondering how I could write long examples :) You two solved my question . Thanks
deceze
@Jared It's simply the semantic markup for code. By default it means browsers display in a monospaced font.
Jared Farrish
I thought that PRE's did that as well in most (all?) browsers, but I guess I'm not sure. I can see the semantic argument.
|
<b>This is bold text</b>instead of This is bold text. Is that right?htmlspecialchars().