HTML | Comments

It is used for inserting comments in the HTML code. Using comments, especially in complex code, is the best practice of coding so that coder and reader can get help for understanding. Commenting in codes is helpful during debugging.

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

Syntax of HTML Comments :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!-- Write your comments here -->

chevron_right



Types of HTML Comments :There are three types of Comments

  1. Single-line comments
  2. Multi-lines comments
  3. Using comment tag
  1. Single-line comments:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
    <head>
      
    </head>
    <body>
      
       <!-- there is a comment -->
       <p>geeksforgeeks.</p>
      
    </body>
      
    </html>

    chevron_right

    
    

    Output:

    geeksforgeeks.

    Here you can see the single-line comment.


  2. Multi-lines comments:
    we can comment by using multilines too.

    Let’s see example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
    <head>
      
    </head>
    <body>
          <!-- 
             This is the
             multiline comment 
             and this is the way of writing comments too.
          -->
            
          <p>GeeksforGeeks</p>
    </body>
    </html>

    chevron_right

    
    

    Output:

    GeeksforGeeks

    Here we can see that in comment section we have used multi lines but still it’s not printed.


  3. Using comment tag:
    There are few browsers that support <comment> tag, Internet Explorer is one of them.

    Let’s see example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
    <head>
      
    </head>   
    <body>
      
      <p>This is <comment>not</comment> Internet Explorer.</p>
      
    </body>
          
    </html>

    chevron_right

    
    

    Output :
    If we use Internet Explorer, then it will show following result :

    This is  Internet Explorer.

    But when we don’t use Internet Explorer, then it will show following result:-

    This is not Internet Explorer

Supported Browser: The browser supported by <!–Comment–> tag are listed bellow :

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.