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

comment-example

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

chrome edge firefox safari opera

Practice Your Knowledge

Which of the following statements about HTML tags are correct based on the information provided in the given URL?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?