Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Friday, November 18, 2011

How to include HTML code snippets in an HTML file?

To have a quick reference at hand, today I was writing a note on how to include software code in my blog posts. I was listing things such as what HTML tags to use and how to use them. To make myself comfortable with HTML, I thought of writing the note as an HTML file. HTML provides <pre>. . .</pre> tags for including verbatim text in your HTML file. However, I quickly realized that any HTML code included in the <pre>. . .</pre> is not treated as verbatim text. It is executed as HTML code. I searched online and after some time, found the following solution.

Instead of using < and > to enclose HTML tags in the code snippet that you want to display, use &lt; and &gt;. For example, to display the <b>. . .</b> tags that you would use to get bold text, type:

    &lt;b&gt; . . .&lt;/b&gt;