References

Beginner-friendly references for web development, with live, editable examples.

The HTML <!--> tag

Element All modern browsers Updated
Quick answer

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

Live 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?
Wrap the text in <!-- and -->, for example <!-- a note -->.
Are HTML comments visible to users?
Not on the rendered page, but anyone can read them in "View Source." Never put sensitive information in them.
Can HTML comments be nested?
No. Comments cannot be nested, and the content must not contain a double hyphen (--).
Should I remove comments in production?
Yes, strip development comments out so pages stay lean and you do not leak internal notes.