Skip to content
Related Articles

Related Articles

Improve Article

HTML Comments

  • Difficulty Level : Basic
  • Last Updated : 04 Feb, 2021
Geek Week

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 helpful to understand the complex code. The comment tag is useful during 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: 

HTML




<!DOCTYPE html>
<html>
 
<body>
    <!--This is heading Tag -->
    <h1>GeeksforGeeks</h1>
   
    <!--This is single line comment -->
    <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 also used by using the (<!– –>).

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 it is not supported by any modern browser.

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.
 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :