Skip to content
Related Articles

Related Articles

HTML Comments

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 21 Jun, 2022

The comment tag ( <!-- Comment-->   ) is used to insert comments in the HTML code. It is a good practice of coding, so that coder and the reader can get help to understand the code. It is useful to understand steps of the complex code. The comment tag is helpful while the debugging of codes.

  • It is a simple piece of code that is wiped off (ignore) by web browsers i.e. , not displayed by the browser.
  • It helps the coder and reader to understand the piece of code used for especially in complex source code.

Syntax: 

<!-- Comments here -->

Types of HTML Comments: There are three types of comments in HTML which are: 

  • Single-line comment
  • Multi-lines comment
  • Using <comment> tag

Single-line comment:  Single line comment is given inside the ( <!–  comment –> ) tag. 

Implementation of the above concept is shown below:

HTML




<!DOCTYPE html>
<html>
 
<body>
    <!--This is heading Tag, It wont be displayed by the browser -->
     
          <h1>GeeksforGeeks</h1>
   
    <!--This is single line comment,It wont be displayed by the browser -->
     
          <h2>This is single line comment</h2>
 
  </body>
 
</html>


Output: Here you can see the single-line comment. Single line comment will not display in the output.

Multi-line comment: Multiple lines can be given by the syntax (<!– –>), Basically it’s the same as we used in single line comment, difference is half part of the comment (” –> “), is appended where the intended comment line ends. 

Implementation of the above concept is shown below:

HTML




<!DOCTYPE html>
<html>
  <body>
    
    <!-- This is
         heading tag -->
    
    <h1>GeeksforGeeks</h1>
 
    <!-- This is
         multi-line
         comment -->
     
    <h2>This is multi-line comment</h2>
   
  </body>
</html>


Output: Here we can see that in the comment section we have used multiple lines but still it’s not printed.

Using <comment> tag: There used to be an HTML <comment> tag, but currently it is not supported by any modern browser.

Implementation of the above browser is shown below:

HTML




<!DOCTYPE html>
<html>
 
<body>
    <comment>This is heading tag</comment>
     
            <h1>GeeksforGeeks</h1>
   
    <comment>This is multi-line
             comment
    </comment>
     
            <h2>This is a comment using</h2>
 
  </body>
 
</html>


Output: 
 

Note: The <comment> tag is not supported by modern browsers.
 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!