HTML <!--...-->Comment Tag


Examples

HTML Comments:

<!--This is a comment. Comments are not displayed in the browser.--> <p>This is a paragraph.</p>

Try it Yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the <!--...--> comment tag.


Tag Definition and Usage Instructions

The <!--...--> comment tag is used to insert comments in the source document. Comments are not displayed in the browser.

You can use comments to explain your code, which helps you edit the code at a later time. This is especially useful when you have a large amount of code.

You can also store program-specific information in the comment content. In this case, this information is invisible to users but available to programs. A good habit is to put script or style elements within comment text, so that old browsers that do not support scripts or styles will not display them as plain text.

<script type="text/javascript"> <!-- function displayMsg() { alert("Hello World!") } //--> </script>

Note:The two forward slashes (//) at the end of the line are JavaScript comment symbols. This ensures that JavaScript does not execute the --> tag.

In addition to their obvious role in the source document, many web servers also use comments to implement features specific to server-side software for documents. These servers can scan documents to find specific character sequences in traditional HTML/XHTML comments, and then take corresponding actions based on commands embedded in the comments. These actions may be as simple as including text from other files (i.e., so-called server-side includes, server-inside include), or as complex as executing other commands to dynamically generate the content of the document.


Differences between HTML 4.01 and HTML5

None.


Standard Attributes

The <!--...--> comment tag does not support any standard attributes.

For more information about HTML standard attributes, please visitStandard Attributes。


Event Attributes

The <!--...--> comment tag does not support any event attributes.

For more information about HTML event attributes, please visitEvent Attributes。

Other Extensions