How to make comments in html. Comments in HTML, CSS, JS and PHP code. Commenting the CSS code
In the work of a programmer, you constantly have to make some notes in the form of comments in order to describe a part of the code or marks 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 at once.
HTML comments
When developing a web page, it is sometimes necessary to hide a part of the code for a while 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 for creating a one-line comment. If you need to "hide" only one line or part of it, you have to use the classic language tools. However, there are several ways to do this.
Standard comment
The easiest way to comment out a piece of code in HTML is to use special character pairs. Before starting a comment, you must specify "". Thus, everything inside this construction will be hidden from the user on page load.
It should be noted that you must be extremely careful when working with a comment. Determining its boundaries, you need to check whether any opening or closing tag has fallen into it, the second part of which has remained outside of it - in this case, the page load will be incorrect. Also, you cannot create several more inside one comment - with this writing, the first signal to complete the commenting part will open the entire subsequent part of the hidden text.
Below is an example of correct spelling:
This is a comment.
Tag
In HTML, you can comment out lines using a special pair of tags -
In the example below, when the page loads in the specified browsers, a white sheet will be displayed, in other programs, the page will say:
This is a comment
.
Unconventional approach
In addition to the classic methods, you can comment out the code in HTML using specific methods. In addition to the basic HTML language structures, scripting and style sheet tags are often specified in the body of the page. Each of them also has its own comment definitions.
Thus, if you enclose the necessary part of the code in one of the specified tags, then inside you can use other methods 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 single-line or multi-line. The former are defined by the "//" construction, which, from the moment of writing these characters, comments the rest of the line. To hide a part of the code, use the syntax description "/ *" to open, and "* /" to close a comment. If the closing construct is not written after the "/ *" symbols, the entire remaining HTML code will be commented out.
The presented example shows a way of non-standard commenting: