Since HTML is officially an SGML application, the comment syntax used in HTML documents is actually the SGML comment syntax. Unfortunately this syntax is a bit unclear at first.
The definition of an SGML comment is basically as follows:
A comment declaration starts withThis means that the following are all legal SGML comments:<!
, followed by zero or more comments, followed by>
. A comment starts and ends with "--
", and does not contain any occurrence of "--
".
<!-- Hello -->
<!-- Hello -- -- Hello-->
<!---->
<!------ Hello -->
<!>
--
" characters, should
always have a multiple of four "-
" characters to be legal.
(And yes, <!>
is also a legal comment - it's the empty comment).
Not all HTML parsers get this right. For example, "<!------>
hello-->
" is a legal comment, as you can verify with the
rule above. It is a comment tag with two comments; the first is empty
and the second one contains "> hello". If you try it in a browser,
you will find that the text is displayed on screen.
There are two possible reasons for this:
-->
" text and thinks the comment ends there.
--
" sequence. Some people have a
habit of using things like "<!-------------->
" as
separators in
their source. Unfortunately, in most cases, the number of "-
"
characters
is not a multiple of four. This means that a browser who tries
to get it right will actually get it wrong here and actually
hide the rest of the document.
For this reason, use the following simple rule to compose valid and accepted comments:
An HTML comment begins with "<!--
", ends with "-->
" and does not contain "--
" or ">
" anywhere in the comment.
HTML 3.2 Reference ~ Elements by Function ~ Elements Alphabetically
Home, Forums, Reference, Tools, FAQs, Articles, Design, Links
Copyright © 1996 - 2006. All rights reserved.