HTML comments are used to insert notes or explanations in the HTML code that are not displayed in the browser.
Comments are helpful for developers to document code, temporarily disable code, or leave reminders.
Syntax
<!-- This is a comment -->Attributes
The HTML comment tag does not support any attributes. Only the content inside <!-- --> is recognized as a comment.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Comment Example</title>
</head>
<body>
<h2>HTML Comment Example</h2>
<!-- This is a comment and will not be displayed in the browser -->
<p>This paragraph is visible to the user.</p>
<!--
Multiple line comment:
1. This is a note for developers.
2. Can temporarily disable code.
-->
<p>This paragraph is also visible.</p>
</body>
</html>
Output
Browser Output
There is no visible output for HTML comments.
Comments only exist in the HTML source and are ignored by the browser when rendering the page.
Browser Support
Chrome | Firefox | Edge | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| ✅Yes | ✅Yes | ✅Yes | ✅Yes | ✅Yes | ✅Yes |
Comments do not appear in the rendered page, but they are visible in the page source.
Notes
- Comments can be used for code documentation, debugging, or temporarily removing code.
- Nested comments are not allowed; HTML does not support
<!-- <!-- nested --> -->. - Avoid leaving sensitive information in comments, as they are visible in the page source.
Conclusion
The HTML comment tag is a developer-only tool for leaving notes or disabling code temporarily. It does not affect the visual layout of the page and is fully supported in all browsers.