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.
3.2.4 Comments – HTML 4.01 Specification から引用
コメント内に二つ以上の連続するハイフン(-)を含むことは避けるべき、というのは割と有名な話。Validationでひっかかりますからね。
ここで目から鱗なのは、コメント開始の <! と -- の間に空白文字を含むことは許されないが、コメント終了の -- と > の間に空白文字を含むことが許される、というところ。ということは
<!--
コメントだよ!!
-- >
みたいなコードが仕様上はOKということ。
では実際のユーザーエージェントはこのコメントをどう解釈するんでしょう。 -- > みたいなコードをコメント終了とみなしてくれるのでしょうか。
手元にあるいくつかのブラウザで表示確認したところ
○→うまくいく、×→うまくいかない
| IE6 / 7 |
× |
| Firefox3 |
○ |
| Safari3 |
× |
| Opera9 |
× |
という結果に。ダメだこれは。。
しかも、大抵のエディタは -- > をコメント終了とみなしてはくれないようで、編集画面のシンタックスハイライトがおかしくなってしまいます。ということで、コメント終了は --> とするのが正解・・・。