In the work of the programmer, you constantly have to make some notes in the form of comments, in order to describe part of the code or notes for the future. Each language has its own syntax, which is why when developing web pages, a frequent problem is not knowing how to comment out a line in HTML or just a small block.
HTML Comments
When developing a web page, sometimes it is necessary to temporarily hide part of the code or make a note for the programmer. In order not to use additional applications, for example, transferring part of the code to another file, you need to know how to comment out a line in HTML.
Unlike most programming languages, HTML does not have a special function or tag to create a one-line comment. If you need to "hide" only one line or part of it, you have to use the classic language toolkit. However, there are several ways to do this.
Standard comment
In HTML, commenting out part of the code is easiest with special character pairs. Before starting a comment, you must specify "<! -", and end it with such characters: "->". Thus, everything that appears inside this design will be hidden to the user when the page loads.
It should be noted that when working with a comment, you must be extremely careful. Determining its boundaries, you need to check if there is any opening or closing tag in it, the second part of which has remained outside it - in this case the page loading will be incorrect. Also, you cannot create several more comments inside one comment - with this writing, the first signal to complete the comment part will open the entire subsequent part of the hidden text.
The following is an example of spelling:
<! -
<p> This is a comment. </p>
->
<comment> tag
In HTML, you can comment out lines using a special pair of tags - <comment>. It is specifically included in the syntax of the language for this purpose, but most popular browsers do not support its work, except for Internet Explorer 8.0. The <comment> tag is useful when some of the information needs to be hidden only for the browser IE 8.0, 4.0 and earlier, and also as a temporary solution during development. What is specific here is that you can comment out part of the code only in the body of the page, that is, inside the <body> tag.
In the example below, when loading the page in these browsers, a white sheet will be displayed, in other programs on the page it will be written "This is a comment" :
<body>
<comment>
<div> This is a comment </div>
</comment>
</body>.
Custom approach
In addition to the classical methods, HTML can comment out the code using specific methods. In addition to the basic HTML language structures, script tags and style sheet tags are often indicated in the body of the page. Each of them also has its own definition of comments.
Thus, if you enclose the necessary part of the code in one of the indicated tags, then you can use other methods inside to comment out part of the code on the HTML page. Such methods are practically not used in modern practice, however, for self-development or, if necessary, to exclude the possible appearance of text on the page, they can be applied.
When using a script tag or style sheet, comments can be either single-line or multi-line. The former are defined by the "//" construct, which since the time of writing these characters has commented on the rest of the line. To hide part of the code, use the syntax description "/ *" to open, and "* /" to close the comment. If the closing construct is not specified after the "/ *" characters, then all remaining HTML code will be commented out.
In the presented example, a way of non-standard commenting is shown:
<script ">
/ * <p> This is a comment. </p> * /
</script>.