The HTML <!--> tag
An HTML comment — <!-- … --> — lets you add notes in the source that the browser ignores and never displays. Comments are still visible in the page source, so never put secrets in them.
Overview
HTML comments are written as <!-- comment -->. The browser parses but does not render them, which makes them handy for leaving notes to other developers, temporarily disabling markup during development, or documenting sections of a page.
They have two syntax rules: comments cannot be nested, and the text inside must not contain a double hyphen (--), which would prematurely close the comment.
Importantly, comments are not private — anyone can read them with "View Source." Never leave passwords, internal URLs, API keys or sensitive notes in comments on a live site, and strip development comments out in production to keep pages lean and avoid leaking information.
Syntax
<!-- This is a comment and is not displayed -->
Example
<!-- Navigation starts here -->
<nav>…</nav>
<!-- Navigation ends -->
Best practices
- Use comments for developer notes and to document sections of markup.
- Do not nest comments, and avoid a double hyphen (
--) inside one. - Never put sensitive information in comments — they are visible in "View Source."
- Strip development comments out in production to keep pages lean.
Frequently asked questions
How do I write a comment in HTML?
<!-- and -->, for example <!-- a note -->.Are HTML comments visible to users?
Can HTML comments be nested?
--).