HTML コメント
土曜日, 12月 22nd, 2007以前HTML 2.0の場合、RFC 1866の”3.2.5. Comments”において次のように定義されていました:
To include comments in an HTML document, use a comment declaration. A comment declaration consists of ‘<!’followed by zero or more comments followed by ‘>’. Each comment starts with ‘- -’ and includes all text up to and including the next occurrence of ‘- -’. In a comment declaration, white space is allowed after each comment, but not before the first comment. The entire comment declaration is ignored.
つまり、
- コメント宣言
<!で始める - コメントは ”- -”で始まり、次に ”- -” が現れるまでの 全ての 文字がコメントとなる
- コメントは0個以上、複数あっても、複数行にわたっても構わない
>で閉じる- コメントの後にはスペースを入れても良いが、最初のコメントの前(<!の直後)にはスペースを入れてはいけない
これが、HTML 4.0で以下のように変更されました。
HTML 4.0においては、コメントの定義は次のようになりました。
HTML comments have the following syntax:
<!-- this is a comment --><!-- and so is this one,which occupies more than one line -->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.
Information that appears between comments has no special meaning (e.g., character references are not interpreted as such).
HTML 4.0 Specification 3.2.4
要するに、コメントは<!- - this is a comment - ->のスタイルだけと覚えていたほうが良いでしょう。改行してもいいけど、その中に複数のハイフンを続けて記述しちゃだめ、ということです。HTML 2.0では許されていた「<!- - ここに - - - - コメントあり - ->」というスタイルは、却下されています。最後の–と>の間にスペースは許されるけど、意味がない気がします。