Comments in HTML

<div id="header">
   <p>Stuff</p>
</div> <!-- END div-header -->

The <!-- --> stuff is the HTML comment. It is a way to add notes into the code which will not display when the HTML is rendered by the browser. In the example above, to signify which opening div tag the closing tag was actually closing.

Comments

  1. User Avatar
    Joseph Watkins
    Permalink to comment#

    That’s awesome Bro, will this work as a comment box ?
    Much appreciated.

    Watkinsservices@live.com

    Thanks again,
    -Joe

  2. User Avatar
    Grant
    Permalink to comment#

    Hey @Joshephy Watkins

    If you are talking about a comment box like what I typed this message in, it won’t. It will just put a note in the HTML code for you to use later (I usually go stuf…… To keep everything organized

  3. User Avatar
    jim
    Permalink to comment#

    Seein how this works

  4. User Avatar
    sumesh
    Permalink to comment#

    gud

  5. User Avatar
    jul
    Permalink to comment#

    thank u.

  6. User Avatar
    υγραεριοκίνηση
    Permalink to comment#

    html comments are particularly useful if you edit a page and you want to find your changes fast. The more detailed these comments are, the better…

    Stamatis – Ygraeriokinisi

  7. User Avatar
    Adam
    Permalink to comment#

    Too bad html editors like Notepad++ can’t handle easy comment-block adding like in the case of JS comments, when you can add them easily by selecting the code and using a shortcut key combination.

    • User Avatar
      kevin
      Permalink to comment#

      Notepad++: Select your code; cntrl+k to comment out; cntrl+shift+k to uncomment.

  8. User Avatar
    Don

    Hi, is there a way I can create a shortcut for this html comment using a MacBook Pro OS Snow Leopard.

  9. User Avatar
    mike
    Permalink to comment#

    Have you ever considered marking blocks like so:

    <div id="blockID">
       <p>Stuff</p>
    </div> <!-- #blockID -->
    
    <div class="blockClass">
       <p>Stuff</p>
    </div> <!-- .blockClass -->
    • User Avatar
      Chris Coyier
      Permalink to comment#

      I do that, but I like to use server side languages instead so it doesn’t need to come over the pipes.

      </div><?php // END div#comments ?>

  10. User Avatar
    John E Wierenga
    Permalink to comment#

    Putting comments in your files is a very good idea. I also use them all the time in my html and even more so in my CSS files for the Joomla sites I develop. All those elements get mixed up in your mind after awhile and when you are adding code or altering pre existing stuff it’s helpful to comment on it so you remember what everything is or what you did to it. Sometimes I make changes then have to go back and tweak them. A comment helps me remember what I did and is a big time saver.

  11. User Avatar
    Mike
    Permalink to comment#

    Nice thing is you can use it like block comment also:

    <!--
      This is my comment on my web page.  This will tell me what
      I was doing when I was last coding.
    -->
    
  12. User Avatar
    Mike
    Permalink to comment#

    awesome…comment preview is odd.



  13. User Avatar
    Dev
    Permalink to comment#

    **is there any short key for giving html comment **

  14. User Avatar
    Granscole
    Permalink to comment#

    I got to learn more about <!–[if lt IE 7 ]>… from his site thanks for all relating to the sharing of knowledge
    Granscole
    http://www.scancomark.com/

  15. User Avatar
    Wan Arep
    Permalink to comment#

    I dont Understand why you all so excited on HTML comment code, it is for SEO ?

    • User Avatar
      Jared
      Permalink to comment#

      No, as has already been pointed out, it is to be used as notes/reminders. Working with a team of developers, I find it especially helpful because if I am working on something and another developer starts to collaborate with me, they can just read my comments in the HTML and know exactly why something is coded the way it is or what the code does. It has nothing to do with SEO.

  16. User Avatar
    Paul Robert Ordinario Martinez
    Permalink to comment#

    Using Dreamweaver, is there a chance to automate to get starting Class or ID as a comment right after closing tag? For instance this is original code

    Is there an option to convert it as

       <!-- end .row -->
    <!-- end .container -->
    

    Thank you in advance.

  17. User Avatar
    Mohamed Yahia
    Permalink to comment#

    using Comments will make your doc more readable for any other team member which may work with it in the future. so i prefer to write code like this

      <!-- title -->
       my title      
    
      <!-- photo -->
    

  18. User Avatar
    John Goold
    Permalink to comment#

    It is not strictly true that comments “aren’t displayed”. Comments aren’t rendered by the browser, but the HTML comments enclosed in HTML comment tags are sent from the server to the viewer’s web browser. They can be seen by using the browser’s “view page source” (or the equivalent).

    So you may want to be careful about what comments you put in your HTML code. As another poster implied, if your HTML code is in PHP files (because you want dynamically generated HTML code), then you can use the tags that enclose PHP code and put a PHP comment within them. The PHP code (i.e. in this case the PHP comments) are stripped out (“interpreted”) on the server and not sent to the viewer’s browser.

  19. User Avatar
    Michael
    Permalink to comment#

    Thank you Chris Coyier for bringing up the topic. Thank you John Goold for pointing out that PHP comments are stripped out server-side.

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Submit a Comment

icon-closeicon-emailicon-linkicon-menuicon-searchicon-tag