How to Display HTML Code in Blog Comments

HTML Code

You can easily display HTML code in a blog comment you leave on a blog. Unfortunately, it does require some minor changes to the HTML before you write it to the comment as regular HTML tags won’t usually be displayed properly, mainly due to security concerns.

When someone would like clarification about a particular piece of code, they attempt to paste it into the comments, but unfortunately, the code is removed and empty white-space is what appears. In this post I will describe how you can easily paste HTML code in your comment, not only on this blog, but probably any blog.

Showing HTML in a Web Page

When you would like to show actual HTML code in a Web page, you can’t simply type the HTML in a Web page and have it show up on the page. The browser would read that code and render it in the browser, instead of showing the actual code.

The trick to display actual code, like I have done with my Blogger template tutorials, is to replace a few characters with literal HTML character codes. You can also do this with blog comments.

Anyone who has coded in HTML knows that HTML is comprised of tags that are used to render information within the browser. The tags are surrounded by the less-than and greater-than brackets. If you want to display HTML code in a web page, or blog comments, you can replace the brackets surrounding the tags with literal HTML character codes.

This table shows the brackets and their corresponding HTML character code:

Character HTML Code
< &lt;
> &gt;

This means that to display this code in your blog comment, or web page:

[code language=”html”]
<html>
<head>
<title>Title of the Web Page</title>
</head>
<body>
<p>Some text.</p>
</body>
</html>
[/code]

You will need to enter the following:

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Title of the Web Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Some text.&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;

If you ever need to display HTML code in a blog comment or on a web page, you can use literal HTML character codes in your HTML to prevent the browser from interpreting and rendering your HTML.

Follow Me