HTML comment tag is used to insert comments in the HTML code. It is good coding practice as it helps developers to better understand complex code. Comments is useful during the debugging of the code.
Syntax
<!-- Comments here -->
Note: The comment tag () is used for both single-line and multiline comments.
html
<!DOCTYPE html>
<html>
<body>
<!-- Paragraph Element -->
<!--HTML Single line Comment -->
<p>Single Line Comment</p>
</body>
</html>
Example 2: Multiline Comment is normally used for debugging by keeping content inside of comments.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Comment Tag</title>
</head>
<body>
<h2>Welcome To GFG</h2>
<p>Multiline Comment</p>
<!--
<p>Default code has been loaded into the Editor.</p>
<p>Default code has been loaded into the Editor.</p>
-->
</body>
</html>
HTML <!– –> Tag – FAQs
Are comments visible to website visitors?
No, comments are not visible to website visitors in the rendered page. However, they can be seen by anyone who views the page’s source code.
Can I use comments to hide HTML code?
Yes, comments can temporarily “hide” code by enclosing it in <!– … –>, but the code will still exist in the page’s source. It will just not be rendered on the page.
Can I use comments inside HTML tags?
No, comments cannot be placed inside HTML tags (e.g., <p <!– This is a comment –>></p>). Comments must be placed outside of the tags.
Is there a limit to how many comments I can use in HTML?
No, there is no limit to the number of comments you can add. However, using too many comments can clutter the code and make it harder to read.
Can comments affect website performance?
No, comments do not affect the performance of the website as they are ignored by the browser during rendering. However, excessive comments in large files may slightly increase page load times, as the browser still has to process them.