HTML comments are used to insert notes, explanations, or reminders into your HTML code. These comments are not visible to users in the browser — they are only seen in the source code.
✅ Syntax
<!-- This is a comment -->
<p>This is visible content.</p>
📍 Result in browser:
Only the paragraph is visible — the comment is ignored.
🎯 Use Cases
- Documenting code for yourself or others
- Temporarily disabling code without deleting it
- Leaving notes for collaborators
- Explaining complex structures or layouts
🛠️ Example
<!-- Navigation Menu -->
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
🚫 Do Not Nest Comments
HTML does not support nested comments. This will break the comment and cause rendering issues:
❌ Invalid:
<!-- Outer comment <!-- Inner comment --> -->
✅ Instead, just use a single comment:
<!-- Outer comment with note about something previously inside -->
🧠 Developer Tip
- Comments can be viewed in the browser’s “View Page Source” or DevTools.
- Don’t put sensitive information in comments — users can still see them in the source.
✅ Summary
Feature | HTML Comments |
---|---|
Syntax | <!-- Your comment here --> |
Visible? | ❌ Not shown in the browser |
Use Cases | Notes, explanations, debugging |
Safe to use? | ✅ Yes, but don’t include passwords |