1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<!-- Thanks for reading the source of this document. Hope you enjoy -->
<!-- what you find here. Please let me know if you find any errors. -->
<HEAD>
<TITLE>HTML comments</TITLE>
<META NAME="description" CONTENT="An explanation of what HTML comments are.">
<META NAME="keywords" CONTENT="html authoring, reference, wilbur, tag overview">
<META NAME="generator" CONTENT="Orb v1.3 for OS/2">
<META NAME="author" CONTENT="Arnoud Engelfriet">
<LINK REV="made" HREF="mailto:galactus@htmlhelp.com" TITLE="Wilbur feedback">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080"
ALINK="#000080">
<H1 ALIGN=CENTER>HTML comments</H1>
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.
<P>
The definition of an SGML comment is basically as follows:
<BLOCKQUOTE>
A <EM>comment declaration</EM> starts with <CODE><!</CODE>, followed by zero or
more comments, followed by <CODE>></CODE>. A <EM>comment</EM> starts
and ends with "<CODE>--</CODE>", and does not contain any occurrence of
"<CODE>--</CODE>".
</BLOCKQUOTE>
This means that the following are all legal SGML comments:
<OL>
<LI><CODE><!-- Hello --></CODE>
<LI><CODE><!-- Hello -- -- Hello--></CODE>
<LI><CODE><!----></CODE>
<LI><CODE><!------ Hello --></CODE>
<LI><CODE><!></CODE>
</OL>
Note that an "empty" comment tag, with just "<CODE>--</CODE>" characters, should
always have a multiple of four "<CODE>-</CODE>" characters to be legal.
(And yes, <CODE><!></CODE> is also a legal comment - it's the empty comment).
<P>
Not all HTML parsers get this right. For example, "<CODE><!------>
hello--></CODE>" 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.
<P>
There are two possible reasons for this:
<OL>
<LI>The browser sees the ">" character and thinks the comment ends
there.
<LI>The browser sees the "<CODE>--></CODE>" text and thinks the comment ends there.
</OL>
There is also the problem with the "<CODE>--</CODE>" sequence. Some people have a
habit of using things like "<CODE><!--------------></CODE>" as
separators in
their source. Unfortunately, in most cases, the number of "<CODE>-</CODE>"
characters
is not a multiple of four. This means that a browser who <EM>tries</EM>
to get it right will actually get it <EM>wrong</EM> here and actually
hide the rest of the document.
<P>
For this reason, use the following simple rule to compose valid and
accepted comments:
<BLOCKQUOTE>
An HTML comment begins with "<CODE><!--</CODE>", ends with
"<CODE>--></CODE>" and does not contain "<CODE>--</CODE>" or "<CODE>></CODE>" anywhere in
the comment.
</BLOCKQUOTE>
<HR>
<CENTER>
<P>
<B><IMG SRC="../icon/wdglogo-small.gif" WIDTH=105 HEIGHT=40 ALT="Web Design Group" ALIGN=RIGHT></B><BR>
<A HREF="../index.html" TITLE="Index for Wilbur">Wilbur index</A> ~
<A HREF="../overview.html" TITLE="Overview of HTML 3.2 tags">Tag overview</A> ~
<A HREF="mailto:galactus@htmlhelp.com" TITLE="Wilbur reference feedback">Feedback</A>
<P>
<SMALL>
Copyright © 1997 <A HREF="http://www.stack.nl/%7Egalactus/">Arnoud "Galactus" Engelfriet</A>.
</SMALL>
</CENTER>
</BODY>
</HTML>
|