What is comment?  

A comment is a piece of text that is used to either explain the work of other codes or make them non-executable temporarily, without affecting the execution of the surrounding code. In HTML, comments are not displayed in the browser. We use comments in HTML to explain the components of a web page and to temporarily disable code blocks so that they are not executed or displayed in the browser. 

 

HTML comment syntax 

We can use following syntax to add comment in our HTML document: 

 

<!-- Write comment  -->

 

Type of comment 

There are two type of comment: 

 

  1. Single-line comment: The single-line comments are usefull for short explanation and temporarily disabling a single line of code. It starts and ends in the same line. 
  2. Multi-line comment: The multi-line comments are usefull for long explanation and temporarily disabling a blocks of code of multiple line. It takes more than one line. 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Comment</title>
</head>

<body>

    <!-- <h1>I'm a single-line comment.</h1> -->

    <!-- <p>I'm a multi-line comment
        because i'm taking more than one line.</p> -->
        
</body>

</html>

 

Key features of comment 

Following are the some key features of a comment: 

 

  1. Syntax: <!-- Write comment -->.
  2. It can be use for both single-line and multiple-line.
  3. It helps to add a short explanation of complex logics to understand code anytime. 
  4. It is used to make a block of code non-executable temporarily. 
  5. Provide context for other developers.