Even quite experienced web authors may be surprised to learn that, technically, there is no HTML element for comments. Instead, comments are a feature of SGML declarations which are functional information for SGML parsers rather than structural parts of documents. Declarations are heavily used in DTDs, for example, to define elements and their allowable attributes, character entities, etc.--actually, almost everything in a DTD is a declaratation. While the start tag for an element opens just with "<", the tag for a declaration must open with "<!". Within a declaration, comments must be opened and closed with "--". Elements and declarations both close their tags with ">". So the syntax for a comment should be:
| <! | -- | This is a comment | -- | > |
| Opens the declaration | Opens the comment | Text of the comment | Closes the comment | Closes the declaration |
Or more legibly, <!--This is a comment-->...
...except that Netscape blew it. For reasons lost to history, the original versions of Netscape allowed comments to skip the closing hyphens: Netscape 1.x would <!--ignore this as a comment> but assume that this was no longer to be commented out.
Not only was this indefensibly incorrect SGML, but it created problems in the real world. For example, Netscape 1.x could not have handled this correctly:
<!--
<p>For 24-hour assistance with your reference
questions, please call Thomas Dowling at home at
614-555-1234.</p>
Hey, should we check with Thomas before we put this on
the home page?
-->
Under Netscape 1.x, the comment would have ended with the first > (following the <p), the rest of the paragraph would appear onscreen, and the web author's career would have ended shortly thereafter.
Unfortunately, many web authors learned to tag comments incorrectly, often writing something like this into the first line of their document:
<html> <!--Written by Chris Jones, 12/12/95> <h1>My Homepage</h1>...
Author Chris Jones would then "check" the document by seeing how it looked in Netscape (1.x), and of course it looked fine. Everything worked just as planned...
...except that Netscape eventually cleaned up their act. In the beta releases of version 2, Netscape corrected the way they read comments. In version 2.x, comments ended only with double hyphens. In the example above, the double hyphens are never found, so everything after the initial <html> tag is treated as part of the comment. In effect the document disappeared.
Needless to say, the Chris Joneses of the world howled bloody murder--the new version was broken, it needed to be pulled from public release until this egregious behavior was fixed, and on and on. Also needless to say, any HTML validation service would have detected the unclosed comment.
The moral of the story is that invalid HTML which looks okay today, in some subset of the world's browsers, carries no guarantees of success even in the next version of the same browser.