1. What are HTML Comments?

HTML comments are an important functionality of HTML markup. They allow to add some content in between the HTML markup that is not displayed to the front end user. While the comment is visible only to the developer of the web page. This HTML tag has importance and let the developer to add his some key points above or in between different sections. So, whenever he visits the markup in future, he will read the comment and promptly understand the succeeding markup. Seethe example below to understand the basic structure of a comment.

Tutorial Contents:

  1. Introduction to HTML Comments
  2. What are the Uses of HTML Comments?

Example

<!--A developer writes a comment in between these dashes.-->

Try in CodeLab

In the above example, you can see the comment has only opening and closing angular brackets unlike regular HTML tags. The content between the two dashes is the content of the comment.

Importantly, note that the sign of exclamation ! comes only after the starting bracket.

2. HTML Comments Usage

The only use of comments is to put reminders or mnemonics in between your code. A comment is only readable by a programmer who has access to the code or markup. Meanwhile comments also help in debugging the source code, which is a great help of HTML markup. So we must use HTML comments properly to get the most out of it. See another example to make it clear.

HTML Comment Detailed Example

<!Doctype html>
<html>
<head>
<title>HTML Comment</title>
</head>
<body>
<h3>HTML Comments Heading</h3>
<!--This paragraph needs a review-->
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
</body>
</html>

Try in CodeLab

The above example will display its result as below. As you can see comments are not shown explaining the usability of this tag.

Output

It is a long established fact that a reader will distract by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.

Note:

Importantly, comments also take part in documentation of a long document. The source code contains many comments and after the completion of the project or document, we can separate all the comments in a separate file manually or using some software to keep a record.

Note:

Since HTML is the extension of SGML, another markup language, so the comments style of HTML is same as that of SGML.
Give Us Your Feedback
OR
If You Need Any Help!
Contact Us