HTML Comments

By | March 2, 2021

An HTML comment is used to provide additional information about the HTML code, and the browser does not display the comment on the interface window.

HTML comment tag

Like other HTML tags, we have a particular tag to write comments. The only purpose of the comments is to provide the information about the code, so if another developer sees the code, he or she could understand what this set of code is supposed to do.

Vamware

Example

<!-- This is a comment -->
The comment tag is an empty tag, so it does not have a paired-end tag. The browser parses the comment tag but does not execute it.

Comments for Notification

Comments are also used for notification and remainder purposes, for instance, you can put a comment on your HTML document as a bookmark refer as to insert a set of code here.
Example
<!-- Create a form Here -->
<p>Please fill the form</p>
<!--Also change the font size of above paragraph  -->

Comments for Debugging

As HTML is not a programming language, so it does not throw an error if there is a bug or poorly written code present in the document. But with the help of comments, we can find that bug or mistake present in the code.
Using the comment tag, we can comment out other HTML elements so the browser will not execute or display that element.
Example
 <!-- we do not have a valid image source for image tag
<img src="" alt="Cat picture">
-->

Summary

  • Comments are generally used to provide information about the code itself.
  • Comments have nothing to do with end-user; they are only for developers.
  • Comments also used to set a notification or remainder in the code.
  • The comment also used to debug the code.
  • Using comment we can comment out another HTML elements.
  • To comment out multiple lines in IDE or Text editor press Ctrl + /

Leave a Reply

Your email address will not be published. Required fields are marked *