When authoring HTML in standards mode, incorrectly formed comments can break your pages, resulting in part or all of your content being commented out. When authoring XHTML or XML, incorrect comments will result in your documents not being able to be displayed at all.
White space is not permitted between the markup declaration open delimiter ("<!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter (">"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.
The following are valid comments in HTML.
<!-- valid html comment --> <!-- valid html comment -- >
Definition: Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string "--" (double-hyphen) must not occur within comments. Parameter entity references must not be recognized within comments. Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
As described in the grammar for comments in XML, a comment has the form
<!-- characters excluding adjacent dashes -->
The following is a valid comment in XML and XHTML.
<!-- valid xml/xhtml comment -->
The following are not valid comments in XML and XHTML.
<!-- invalid -- xml comment --> <!-- invalid xml comment ---> <!-- invalid xml comment -- >
- HTML 4.01 Recommendation: 3.2.4 - Comments
- XML Recommendation: 2.5 - Comments
- HTML Tutorial from w3schools: Comment-Tag
Original Document Information
- Last Updated Date: May 19th, 2003
- Copyright © 2001-2003 Netscape. All rights reserved.