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

HTML Reference Manual

HTML tag大全

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

This article will guide you through 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>基础教程网(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 to see ‹/›

Browser support

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

ChromeAndroidFirefoxIEEdgeOperaSafari

Tag 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 helps you edit the code in the future. This is especially useful when there is a lot of code.

You can also store customized information for the program in the comment content. In this case, this information is invisible to the user, 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>基础教程网(oldtoolbag.com)</title> 
</head>
<body>
<script type="text/javascript">
<!--
function displayMsg()
{
  alert("Hello World!")
}
displayMsg();
//-->
</script>
</body>
</html>
Test to 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's server-side software. These servers can scan the document, from traditional HTML/In XHTML Comments, find a specific character sequence and then take appropriate actions based on the commands embedded in the comments. These actions may include including text from other files (i.e., server-side includes, server-inside include),也可能是复杂地执行其他命令去动态生成文档的内容。

javascript inside include), or it may execute other commands to dynamically generate the content of the document.-- //--> function

The following syntax is often seen when using 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 the 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. Even if JavaScript fails, it will not display the source code 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.