How to Create a HTML Comment

In this article we will discuss how to add comments to an HTML page. The commentaries are very important in the development of an application, it allows mainly to be found in the proofreading of its code but also for sharing it. Without further delay, let’s go to the explanations !
HTML Comments
Comments are used to explain parts of an HTML page. They help to understand the code and increase its readability. It is also used to test parts of its code to temporally exclude them instead of having to delete them.
An html comment is included between the <!- – and – -> tags :
<!-- Insert a comment here -->
The tag begins with an exclamation mark but is not present at the end.
Note : Browsers ignore this tag and therefore do not display its content to visitors to the html page.
Example :
<div>
<p>This is the visible part of the article.</p>
<!-- Welcome to the amiradata ! Comment the article :) -->
</div>
Here is the page that the user will see during his visit on the page :

It is also important to know that comments can be used anywhere in the html document, with the exception of two tags :
- The <title> tag
- The <style> tag. Indeed, the CSS language uses another syntax for comments.
Multiline Comments
HTML accepts multi-line comments. It uses the same syntax for single line comments :
<div>
<p>This is the visible part of the article.</p>
<!-- Welcome to the amiradata !
Comment the article :)
-->
</div>
Browser Support
Here is the list of browsers that support this tag :
- Chrome
- Firefox
- Opera
- Safari
- Internet Explorer
- Edge
More details in the image below:

Note: there is an HTML < comment > tag that was used in the past, but it is no longer supported by any modern browser.
Do not use it for your comments!
Conclusion
Now you know how to create a comment in HTML. Be aware that you should not insert too many comments in your code (I’m talking about hundreds of comments 🙂 , Indeed this has the effect of increasing the size of the HTML is therefore to increase the time to run the page.
If you wish to have more information on the HTML language, click here.
Feel free to leave a comment, it’s always a pleasure! 🙂
Comments
Leave a comment