The HTML5 Comment Tag

The HTML5 <!--…--> tag is mainly utilized for adding comment in the source code. However, do not expect the comment to appear on the web browser. Utilizing the HTML5 <!--…--> tag is important for adding comments which will serve as notes regarding your code. That way, if alterations have to be done in the future, it is useful as a reference. When there are multiple source codes, this tag will avoid confusion.

Another way to use the HTML5 <!--…--> tag is to be able to hide the scripts in browsers that do recognize it. It is a tag that would avoid showing the script as a plain text.

When used for scripts, it is necessary to add // at the end of the comment. The // is a comment symbol in JavaScript. It would look like this:

<scripttype="text/javascript">

<!--

function displayMsg()

{

alert("Comment should be placed here!")

}

//-->

</script>

Adding the // is necessary so that JavaScript would not interpret it as the --> tag.

The HTML5 <!--…--> tag is compatible with the different main browsers that are being utilized these days like Internet Explore, Firefox, Opera, Safari and Google Chrome.

Using the <!--…--> tag is the same for both HTML5 and HTML4.01. This tag does not support the Global Attributes and Event Attributes.