HTML注释可用于将有关代码中特定点的注释留给您自己或其他开发人员。可以使用来启动<!--和终止它们-->,如下所示:
<!-- I'm an HTML comment! -->
它们可以内联到其他内容中:
<h1>This part will be displayed <!-- while this will not be displayed -->.</h1>
他们还可以跨越多行以提供更多信息:
<!-- This is a multiline HTML comment. Whatever is in here will not be rendered by the browser. You can "comment out" entire sections of HTML code. -->
但是,它们不能出现在另一个HTML标签中,如下所示:
<h1 <!-- testAttribute="something" -->>This will not work</h1>
这将产生无效的HTML,因为整个<h1 <!-- testAttribute="something" -->块将被视为单个开始标签h1,其中包含一些其他无效信息,然后是一个>不执行任何操作的结束括号。
为了与尝试将HTML解析为XML或SGML的工具兼容,注释的正文不应包含两个破折号--。