Skip navigation
Currently Being Moderated

HTML 5 Comment Syntax

May 8, 2013 4:33 PM

Tags: #comment_syntax

I'm looking for a way to add comments to HTML 5, meaning text that is not executed but is there to help understand the programming. In CSS I see /* comment */  used for that purpose. In HTML, I see comments, but it's not clear how they are flagged as comments.


For example, I've seen <!-- comment-->, but that syntax also seems to be used for conditional statements that are executed, as in <!--[if gt IE 8]><!-->. That looks like it's written as a comment, but obviously it's meant to be executed. I think.  I just want to be able to safely add comments to the HTML code, but I need help with the syntax. THanks!

  • Currently Being Moderated
    May 8, 2013 4:54 PM   in reply to calpolyjeff

    So far you have everything right.


    <!--this is an HTML comment-->

    /**this is a CSS Comment**/

    //This is a single line comment in JavaScript or PHP code


    Conditional comments for IE are ignored by ALL browsers except IE9, 8, 7, 6.

    IE10 no longer pays attention to conditional comments.




    Nancy O.

    Mark as:
  • Currently Being Moderated
    May 9, 2013 9:22 AM   in reply to calpolyjeff

    Comments are ignored.  Scripts inside comments won't execute.


    IE Conditional Comments are hacks.  They always begin with an IF statement which only IE browsers see. 

    <!--[if lt IE 9]>


    Why did MS do this?  To mitigate the fact that IE browsers are not standards compliant.  Instead of fixing the problem like they should have done a decade ago, MS decided to make a window so developers could workaround the serious shortcomings in these inferior browsers.  Nice, huh? 


    IE10 promises to be standards compliant thus won't need any hacks.  Cross your fingers.



    Nancy O.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points