HTML <!--...-->
Comment Tag
Example
HTML Comment:
<!--This is a comment, which will not be displayed in the browser-->
<p>This is a paragraph</p>
Browser Support
All major browsers support the <!--...-->
comment tag.
Tag Definition and Usage
The <!--...-->
comment tag is used to insert comments in the source code. Comments are not displayed in the browser.
You can use comments to explain your code, which can help you edit the code at a later time. This is particularly useful when dealing with large amounts of code.
You can also store information tailored for the program within the comment content. In this case, the information is invisible to users but available to the program. A good practice is to place comments or style elements within comment text, so that older browsers that do not support scripting or styling do 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 command 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 use comments to implement document server-side software-specific features. These servers can scan the document, find specific character sequences in traditional HTML/XHTML comments, and then take actions based on commands embedded in the comments. These actions might be simple inclusions of text from other files (known as server-side includes), or more complex commands that dynamically generate document content.
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 visit Standard Attributes.
Event Attributes
The <!--...-->
comment tag does not support any event attributes.
For more information about HTML event attributes, please visit Event Attributes.