Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

<!–…–> comment tag


May 04, 2021 HTML Reference Manual


Table of contents


HTML slt;!--...-- and comment labels

Label definition and instructions for use

The comment !--...-- is used to insert comments into the source document. Comments do not appear in the browser.

You can use comments to interpret your code, which will help you edit your code at a later time. Especially in situations where the amount of code is large is useful.

You can also store information tailored to the program in the comment content. I n this case, this information is not visible to the user, but is available to the program. It is a good practice to put comments or style elements into the comment text so that older browsers that do not support scripts or styles do not display them as plain text.

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

<!–…–> comment tag
html Comment code analysis diagram

Note: The last two forward slashes (/) on the command line are JavaScript comment symbols. This ensures that JavaScript does not execute the --gt; tag.

In addition to playing a significant role in source documents, many Web servers also use annotations to implement features specific to document server-side software. T hese servers can scan documents, find specific sequences of characters from traditional HTML/XHTML comments, and then act according to the commands embedded in the comments. These actions can be simply including text in other files (so-called server-side inclusion, server-inside), or they can be the complex execution of other commands to dynamically generate the contents of a document.


HTML comments:

<! - This is a comment, the comment is not displayed in your browser ->

<p>这是一个段落</p>

Try it out . . .

Browser support

<!–…–> comment tag <!–…–> comment tag <!–…–> comment tag <!–…–> comment tag <!–…–> comment tag

All major browsers support the !--...-- and comment tags.


The difference between HTML 4.01 and HTML5

No.


The standard property

The comment !--...-- does not support any standard properties.

For more information about HTML standard properties, visit Standard Properties.


The event property

The comment !--...-- does not support any event properties.

For more information about HTML event properties, visit Event Properties.


The role of HTML comments

A complete set of code can be dazzling, and when a programmer wants to modify a part, it can take a lot of time to find that part of the code. J ust as we mark and mark important parts in an article, you can use the Comment Label in your code to annotate some code. C omment labels do not appear in the visual interface because they are just a little thing that programmers use to annotate instructions, to explain some code programs, and to allow laterrs to quickly take over and understand their usefulness.

Code example

<!--

这是w3cschool网站首页头图

-->

<img src="http://statics.w3cschool.cn/images/w3c/intro.png"  alt="w3cschool" />


Results:

<!–…–> comment tag

Analytical:

1, from the above example we can see that the text of the comment section is missing after running, but if you look at the source code you can see the content of this part.

<!--

这是w3cschool网站首页头图

-->

2, in the example also appeared in the "picture path" alt , "picture name" /

The src property of the label is required. Its value is the URL of the image file, which is the absolute or relative path of the file that references the image.

How to view comments:

1, first of all, on the web page to click the right mouse button, choose to view the source code.

<!–…–> comment tag


2, after entering the source code page, press ctrl-f will appear search box


<!–…–> comment tag


3, enter the "!--" you can find the comment label! I n addition to being used for illustration, comment labels are often used to comment out code that is not needed to be displayed for the time being. F or example, if you do an event and you don't open the page until 10 a.m. tomorrow, you can write and upload the code in advance, and then delete the comments at the beginning of the event to make changes to the site more quickly.


Of course, the result of this search is to show all the comment labels, if the code owner himself wants to find a comment label, in the search box directly enter the comment label text content.


<!–…–> comment tag


I've heard that many programmers like to write funny comment tags, such as:

<!--

下面这串代码是经理要求加的,目的就是为了拖慢网页加载速度,好再坑客户一笔优化网站的钱

-->

<link rel="stylesheet" href="//www.w3cschool.cn/foo.css" type="text/css"> 

<!--

这个页面的代码都不要动!不要动!不要动!我动了之后就后悔了

-->

......

<!--

这段代码好像是没用的,但是我不敢删掉

-->

......

Above is the html comment label, the comment label and another form of expression, used in the C language.

Comments in the C language are generally divided into two types, one beginning with "/", adding the comment content in the middle, and ending with a paragraph comment with "/". Comments are made between "/" and "
/*这里是注释标签*/
The other begins with a "//" and is followed by a single line of comments for the comment content. Comments are made after "//".
//这里是注释标签