Treehouse: Grow your CSS skills. Land your dream job.

Last updated on:

Comments in HTML

<div id="header">
</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.


  1. Joseph Watkins
    Permalink to comment#

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

    Thanks again,

  2. 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. jim
    Permalink to comment#

    Seein how this works

  4. sumesh
    Permalink to comment#


  5. jul
    Permalink to comment#

    thank u.

  6. υγραεριοκίνηση
    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. 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.

  8. Don

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

  9. mike
    Permalink to comment#

    Have you ever considered marking blocks like so:

    <div id="blockID">
    </div> <!-- #blockID -->
    <div class="blockClass">
    </div> <!-- .blockClass -->
    • 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. deep Sinha
    Permalink to comment#

    awesome Stuff bro keep it up my website superblogger

  11. 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.

  12. 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.
  13. Mike
    Permalink to comment#

    awesome…comment preview is odd.

  14. nebz
    Permalink to comment#

    I’ve never seen people get so excited about comments. geez.

  15. Dev
    Permalink to comment#

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

  16. 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

  17. Wan Arep
    Permalink to comment#

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

    • 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.

  18. avalon4me
    Permalink to comment#

    That was an easy one, heh ;)

  19. 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.

  20. 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 -->

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";