How to comment out a line in HTML?

Table of contents:

How to comment out a line in HTML?
How to comment out a line in HTML?

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, not knowing how to comment out a line or a small block at once in HTML is a common problem.

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, moving part of the code to another file, you need to know how to comment out a line in HTML.

html comment out
html comment out

Unlike most programming languages, HTML does not have a special function or tag for creating a single 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

Comment out the part in HTMLThe easiest way to code is by using special pairs of characters. Before the beginning of the comment, you must specify "". Thus, everything inside this construct will be hidden from the user when the page loads.

html comment out the code
html comment out the code

It is worth noting that when working with a comment, you must be extremely careful. When defining its boundaries, you need to check if any opening or closing tag has got into it, the second part of which has remained outside it - in this case, the page will not load correctly. Also, you cannot create several more within one comment - with this writing, the first signal for the completion of the commenting part will open the entire subsequent part of the hidden text.

Below is an example of correct spelling:

This is a comment.


In HTML, you can comment out lines using a special pair of tags -. It is specifically included in the language syntax for this purpose, but most popular browsers do not support it, with the exception of Internet Explorer 8.0. The tag is useful when some information needs to be hidden only for IE 8.0, 4.0 and earlier browser versions, and also as a temporary solution during development. The specific point 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, the page will say "Thiscomment":

This is a comment

Out of the box

In addition to the classical methods, you can comment out code in HTML using specific methods. In addition to basic HTML language structures, script tags 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 the 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.

how to comment out a line in html
how to comment out a line in html

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, from the moment these characters are written, comments on the entire remaining line. In order to hide part of the code, you should use the syntax description "/" to open, and "/" to close the comment. If the closing construction is not written after the "/" characters, then the entire remaining HTML code will be commented out.

This example shows a way to make custom comments:


This is a comment.


Popular topic

Editor's choice

  • Let's build iOs apps! Overview of programs, instructions, recommendations
    Let's build iOs apps! Overview of programs, instructions, recommendations

    Today more and more people are starting to dive into the world of IT. A fairly common industry is the creation of various kinds of mobile applications. Quite a lot of different games and programs have already been developed for Android. It is because of this that many developers have begun to move to the iOS platform. This is not a very crowded industry where you can find a lot of clients and make quite a lot of money

  • Moving WordPress to another hosting: features, procedure
    Moving WordPress to another hosting: features, procedure

    Today, every person who has his own website on the Internet may face the problem that he will need to transfer the site to another hosting. There can be many different reasons for this. Of course, the most common of them is dissatisfaction with the services provided. If you can't take it anymore, then you need to act. This is a rather long procedure. If you do everything step by step, you can safely transfer the site, and not redo everything several times

  • How to pass on the rights in "SAMP RP"?
    How to pass on the rights in "SAMP RP"?

    Every person who plays online games is trying to upgrade his character and achieve many interesting things. Users who prefer SAMP try to get a driver's license even from the first level. Experienced players may not take the exam, but simply go to the instructor and buy rights from him. Of course, it will be somewhat more expensive, but this way you can save your time. How to pass on the rights to "SAMP"? Let's review this

  • How to turn off the camera on a laptop? 3 easy ways
    How to turn off the camera on a laptop? 3 easy ways

    Today, hacking has begun to actively develop in the world of information technology. An experienced hacker can get into almost any computer and get the user's information, provided, of course, the laptop is connected to the network. Recently, users have been complaining that their webcam turns on by itself. This way hackers can see where you are and what you are doing. In the future, this information can be used in completely different ways, up to the fact that you become a star on YouTube

  • Shared AppStore Account Features
    Shared AppStore Account Features

    A shared App Store account has many features. It allows users to install games and applications, as well as watch movies in high definition. Shared accounts give official access to app and game downloads for Apple devices (iPhone, iPad, iPod Touch)