HTML comments wrap between <!-- and -->. They are delivered to every visitor—treat them as public documentation.
Rules
- Comments cannot nest; the first
-->closes the comment. - Avoid
--inside comments (parser edge cases in SGML legacy). - Dynamic templates still leak comments to DevTools—never stash secrets.
<!-- Section: hero -->
<section id="hero">…</section>
Good uses
- Explaining unusual markup decisions to teammates.
- Temporarily isolating chunks during debugging (remove before release).
Better alternatives
- Server-side comments or templating comments that never reach HTML output.
- Git commit messages referencing ticket IDs.
Rare-but-painful pitfalls
- Comments accidentally containing
-->prematurely close sections—validators catch some cases, reviewers catch others. - Large commented-out bundles still download and parse—affecting Lighthouse HTML size budgets.
Rendered example
The comment itself is not visible in the page UI.
Important interview questions and answers
- Q: When should you use `strong` vs `b`?
A: Use `strong` for semantic importance; use `b` only for stylistic offset without importance semantics. - Q: Why is `target="_blank"` usually paired with `rel="noopener"`?
A: It blocks the opened page from controlling the opener via `window.opener`, improving security. - Q: Why avoid fake buttons built with ``?
A: Anchors are for navigation; actions should use `
Pitfall: Comments are visible in View Source—never put secrets in HTML comments.