ComputersProgramming

How in HTML to comment out a line?

In the work of the programmer, you constantly have to make some notes in the form of comments, in order to describe some of the code or marks for the future. Each language has its own syntax, which is why when developing web pages, the frequent problem is not knowing how to comment out a line in a HTML or just a small block.

Comments in HTML

When developing a web page, sometimes it is necessary to temporarily hide some 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 the line in HTML.

Unlike most programming languages, HTML does not have a special function or tag to create a single-line comment. If necessary, "hide" only one line or part of it, you have to use the classic language toolkit. Nevertheless, you can do this in several ways.

Standard comment

In HTML, commenting out a piece of code is easiest by using special character pairs. Before the beginning of the comment it is necessary to specify "". Thus, everything that appears inside this structure will be hidden for the user when the page loads.

It should be noted that when working with the commentary it is necessary to be extremely attentive. Defining its boundaries, it is necessary to check whether any opening or closing tag entered it, the second part of which remained outside of it - in this case the page loading will be incorrect. Also, you can not create a few more comments inside the same comment - with this writing, the first signal to the end of the comment section will open the entire subsequent part of the hidden text.

Below is an example of the correct spelling:

This is a comment.

->

The tag

In HTML, you can comment out lines by using a special pair of tags - . It is specifically included in the syntax of the language for this purpose, however most popular browsers do not support it, except for Internet Explorer 8.0. The tag is useful when you need to hide some of the information for the IE 8.0, 4.0 and earlier browser only, and also as a temporary development solution. Specific here is the moment that you can comment out part of the code only in the body of the page, that is, inside the tag.

In the example below, when the page loads in the specified browsers, a white sheet will be displayed, while in the other programs the page will say "This is a comment" :

This is a comment

.

Non-standard approach

In addition to the classic ways, in HTML you can comment out the code using specific methods. In addition to the basic language structures of HTML, the body of the page often specifies script tags and style sheet tags. Within each of them there are also their own definitions of comments.

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 a 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 first ones are defined by the "//" construct, which, from the moment of writing these characters, comments on the rest of the line. To hide some of the code, use the "/ *" syntax for opening, and "* /" to close the comment. In the event that after the "/ *" symbols the closing design is not written, all the remaining HTML-code will be commented out.

In the example shown the way of non-standard commenting is shown: