Comments in HTML for web development

Comment is a piece of code which is ignored by any web browser. It is added to the code to add extra information about the code. It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.

With the passage of time, human mind skips many things and forget the meaning of its own written code. But, if the comments are added to the code at the time of creation of code may be beneficial in future.

HTML comments are placed in between <!– … –> tags. So, any content placed within <!– … –> tags will be treated as comment and will be completely ignored by the browser. The comments will not be executed while running code.

<!DOCTYPE html>
<html>
<head>  <!-- Document Header Starts -->
<title>This is document title</title>
</head> <!-- Document Header Ends -->
<body>
<p>Document content goes here.....</p>
</body>
</html>

Multiline Comments

We have seen single line comments in our code above but HTML supports multi-line comments as well. Multi line comments are used when there is need to use continuous comment in two or more lines.

You can comment multiple lines by the special beginning tag <!– and ending tag –> placed before the first line and end of the last line as shown in the given example below.

<!DOCTYPE html>
<html>
<head>  
     <title>Multiline Comments</title>
</head> 
<body>
      <!-- 
         This is a multi line comment and it can
         span through as many as lines you like.
      -->
      <p>Document content goes here.....</p>
   </body>
</html>

It results as : Document content goes here…..