The HTML comment tag is used to write comments in main code file. The comments that we write are not displayed on the browser like other HTML content. It is only for programmers.
Table of Contents
How to write HTML Comment Tag
To write comment using HTML Comment Tag is very simple, below is the example.
<!DOCTYPE html>
<html>
<body>
<!--I am a comment. I live inside HTML Comment Tag.
Read me to know about this code. This piece of code
is about HTML Comment Tags.-->
</body>
</html>
HTML Comment Tag Usage
Comments are very helpful and it's always suggested to write comments in your code. Comments can tell you about the purpose of a particular piece of code which can help you when you edit the code in future.
Comments act as Note to any programmer who reads it or works on it. Comment tag is used to explain your code.
You can use HTML comment tag to hide or comment out the scripts and your browser won't notice it.
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
<!--
function displayMsg() {
alert("This Script won't be executed")
}
//-->
</script>
</body>
</html>
Note: HTML Comment Tag doesn't support standard or event attributes.
HTML Comment Tag Video
Watch our video on comment tag and subscribe our Youtube Channel.