HTML Comments

The HTML comments are used to indicate sections of a document or insert any notes explaining the code. They help you and others understand the code and increases its readability. The comment tag can also be used to exclude temporary code blocks instead of deleting them.

For defining HTML comments we use the <!-- ... --> tag. The browsers ignore this tag and do not show its content to the users.

HTML comments can be used anywhere in the documents except for the <title> tag. They do not work within the <style> tag either, as CSS uses another syntax for comments.

Syntax

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

Example

<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document.</title>
  </head>
  <body>
    <h1>The main heading</h1>
    <!--  <p>We want to hide this part of the code temporary. </p> -->
    <a href="https://www.w3docs.com">Homepage</a>  
    <!--  <p>This is a link to the homepage</p> -->
  </body>
</html>

Result