Comments in HTML are often used to explain markup. It will help you and others quickly and easily select or find specific parts of a document when editing source code. The browser does not display comments.
We should make good use of comments when writing code, because a complete HTML document often consists of hundreds or thousands of lines of code. When we want to modify a certain part of it, it may take a long time to find the part we want to modify. place. With comments, it's different. We can divide the program into several parts according to functions or other conditions and mark them with comments. This can help you and others read your code and improve the readability of the code.
<html><body><!--This is a comment. Comments will not be displayed in the browser. --><p>This is an ordinary paragraph. </p></body></html>
Tip: There is an exclamation point in the opening tag, but not in the closing tag. The browser won't display the comments, but they can help document your HTML document.
1. Single line comments
In HTML you can use <!-- --> to add comments in your code. Everything between <!-- and --> will be considered a comment. The sample code is as follows:
<!DOCTYPEhtml><html><!--head starts--><head><metacharset=UTF-8><!--The current document uses UTF-8 encoding--><title>How to write HTML comments</title ></head><!--End of head--><!--Start of body--><body><!--A paragraph of text--><p>Welcome to Dotcpp programming HTML tutorial, please remember the address :https://www.dotcpp.com/course/html/</p></body><!--End of body--></html>
Presented as follows:
Comments can appear anywhere in an HTML document, including at the beginning of the document, at the end of the document, in the middle of the document, outside the tag, within the tag content, etc.
2. Multi-line comments
Previously we mainly demonstrated single-line comments, but multi-line comments are also supported in HTML. The difference between multi-line comments and single-line comments is not big. We only need to ensure that the content of the comment is between <!-- and -->, as shown below:
<!--Multi-line comments-->
In addition to explaining the code, comments can also be used to annotate the code in the program. For example, if you do not want a certain piece of code to be executed, you can comment it out first so that the browser will not execute the code.
3. Conditional comments
You may occasionally find conditional comments in HTML:
<!--[ifIE8]>....someHTMLhere....<![endif]-->
Conditional comments define HTML tags that only Internet Explorer executes.
software program label
Various HTML software programs can also generate HTML comments.
For example, the <!—webbot bot—> tag is surrounded by HTML comments created by FrontPage and Expression Web.
As a rule, the existence of these tags helps support the software that created them.