Useful Tips

How to comment out a line in HTML?

Pin
Send
Share
Send
Send


Comments in html are set using the construct. Visually on the page they are not displayed at all.

Comment in html can be stretched over several lines

The comment will continue until the first closing construction -> is met. Nested comment is not supported.

Comments can be written right inside the tags:

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 "". 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, it is necessary to check whether any opening or closing tag has got into it, the second part of which has remained outside it - in this case the page loading will be incorrect. Also, you can’t 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:

In HTML, you can comment out lines using a special pair of tags -. 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. It is useful to use the tag when some of the information needs to be hidden only for the browser IE 8.0, 4.0 and earlier versions, 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 tag.

In the example below, when loading the page in the specified browsers, a white sheet will be displayed, in other programs on the page it will be written "This is a comment":

Pin
Send
Share
Send
Send