HTML <!-- ... --> tag

The <!-- ... --> tag is used to insert comments in an HTML code. Its content is ignored by the browsers and is not displayed by them. However, the comments are visible to anyone who views the page source code.

HTML comments point out document sections or insert notes explaining the code. The comment tag can also be used to exclude short-term code blocks instead of deleting them.

Comments can be used anywhere in the documents except for the <title> tag.

Syntax

Comments are written between <!-- and --> symbols.

Example of the HTML comment tag:

<!DOCTYPE html>
<html>
  <head>
    <title>Example of using the comment tag.</title>
  </head>
  <body>
    The content of the page. 
    <!-- This is our comment, that is not displayed on the browser. --> 
  </body>
</html>

Result

The comment tag can be used for “hiding” scripts from browsers without any support for scripts.

<script type="text/javascript">
  <!--
  function displayMsg() {
    alert("Comment tag")
  }
  //-->
</script>

In the example above, the two forward slashes that are located at the end of the line (//) is the comment symbol of JavaScript . This stops JavaScript from running the --> tag.

The comment tag doesn’t support the Global Attributes.


Browser support



Do you find this helpful?

Related articles