HTML Comments

Bookmark
Learn about how to add comments in HTML documents.

Comments are used to annotate source code. It will add information describing the code and comments will not be displayed in browser. It is possible to look at the source code of the HTML pages using the option provided in a web browser. These comments will be visible when a user does the 'view source'. Comments help the programmer to understand purpose of the code.

  • HTML comments starts with <!-- tag, followed by text description and ends with -->.
  • Single line or multiple lines can be commented by enclosing them between the comments tag.
  • Comments tag do not have any attributes.

HTML Comments Example

<!DOCTYPE html>
<html>
<head>
<title>HTML Comments Example</title>
</head>
<body>
    <p>Comments are not displayed in browser. <!-- this commented part will not be displayed. --></p>
</body>
</html>

Output

Comments are not displayed in browser.

Cannot Nest HTML Comments

HTML comments cannot be nested, that is a comment cannot be inserted inside another comment. Following is an example of invalid nested comment.

<p>Comments should not be nested. <!-- comment started <!-- another comment inserted --> parent comment --></p>