In this section, we will see what comments are and how to use them in HTML.
How to HTML Comment and What is Comment Tag in HTML?
Comments are a way of explaining the structure and elements within an HTML file to other developers. For example, let’s say you’ve written 1000 lines of HTML code and now your colleague is about to take control of what you’ve done and develop it from there. In such cases, you can use comments to explain to what extent you’ve worked on the source code and in what parts there are still works to be done!
In short, comments are for developers’ communication only and not for computers! This means, when a computer faces a comment, it will simply ignore it and move on to the rest of HTML codes.
HTML Comment Tag Syntax:
<!-- Comment -->
HTML Comment Tag Values
You start with <!– and end with –>. In between, you put the comments you want.
HTML Comment Note:
A comment can be multiline as well. Just remember to start with <!– and after you’ve set the comments, put the –>.
Example: comment in HTML
Example: multiline comments in HTML
Commenting out in HTML
Other than setting a comment for other developers, sometimes we want to disable the use of one or more HTML elements in a source code without actually removing them! This is where comments are useful as well!
In such cases, all we need to do is to simply put the <!– at the beginning of the unwanted source code and –> at the end of it.
Example: commenting out HTML
In this example, the <p> element and its value are commented out and so it won’t be rendered on the page.