HTML | Comments

It is used for inserting comments in the HTML code. Using comments, specially in complex code, is the best practice of coding so that coder and reader can get help for understanding.

  • It is simply piece of code which is wiped off by web browsers i.e, not displayed by browser.
  • It gives help to coder / reader of code to identify piece of code 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




Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

geeksforgeeks.



Types of HTML Comments :



  1. Multilines comments
  2. Using comment tag
  1. Multilines 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>
    <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.


  2. Using comment tag :
    There are some browsers that support comment tag.

    Let’s see example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
          
    <body>
      
      <p>This is <comment>not</comment> geeksforgeeks.</p>
      
    </body>
          
    </html>

    chevron_right

    
    

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

    This is  geeksforgeeks.

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

    This is not geeksforgeeks


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.