English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <!--...--> Comment tags

This article will introduce you to the use of HTML comments. Compared to other programming languages, HTML comments are a bit more complex. HTML comment tags are<!--...--> All content within this comment tag will not be displayed by the browser

Online Example

HTML Comment:

!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>Basic Tutorial Website(oldtoolbag.com)</title> 
</head>
<body>
<!--This is a comment, comments are not displayed in the browser-->
 
<p>This is a paragraph content</p>
</body>
</html>
Test and see ‹/›

Browser support

All mainstream browsers support <!--...--> Comment tags.

ChromeAndroidFirefoxIEEdgeOperaSafari

Label definition and usage instructions

<!--...--> Comment tags are used to insert comments in the source document. Comments are not displayed in the browser.

You can use comments to explain your code, which is helpful for you to edit the code in the future. This is especially useful when the amount of code is very large.

You can also store customized information for the program in the comment content. In this case, this information is invisible to users, but available to the program. A good habit is to put comments or style elements in the comment text, so as to avoid old browsers that do not support scripts or styles from displaying them as plain text.

!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>Basic Tutorial Website(oldtoolbag.com)</title> 
</head>
<body>
<script type="text/javascript">
<!--
function displayMsg()
{
  alert("Hello World!")
}
displayMsg();
//-->
</script>
</body>
</html>
Test and see ‹/›

Comment:The last two forward slashes (//)is the JavaScript comment symbol. This ensures that JavaScript will not execute --> tag.

In addition to their very obvious role in the source document, many web servers also use comments to implement special features of the document server software. These servers can scan the document, from traditional HTML/Find a specific character sequence in the XHTML comment and then take the corresponding action based on the command embedded in the comment. These actions may include text from other files (i.e., server-side includes, server-inside include),也可能是复杂地执行其他命令去动态生成文档的内容。

javascript inside include), it may also be used to execute complex commands to dynamically generate the content of the document.-- //--> Function

The following is a common way to use JavaScript in HTML:

<script type="text/javascript">
<!--
XXXXXXXX Content omitted XXXXXX
//-->
</script>

This is to prevent some browsers that do not support JavaScript from causing JavaScript code to appear directly on the page, affecting the appearance.
Therefore, using HTML comments to enclose JavaScript code will also be treated as comments if the browser does not support JavaScript. Although JavaScript may fail, it will not cause the source code to be displayed on the page.

Standard Attributes

<!--...--> Comment tags do not support any standard attributes.

For more information about HTML standard attributes, please visit Standard Attributes.

Event Attributes

<!--...--> Comment tags do not support any event attributes.

For more information about HTML event attributes, please visit Event Attributes.