An HTML comment is a note in your markup that the browser does not display on the page. Use it to explain code, label sections, or temporarily disable HTML while you debug.
Comments use the <!-- --> delimiters. There is no<comment> element — comments are syntax, not a tag like <p> or <div>.
Baseline · Widely available.
Not deprecated. Core HTML comment support is stable in every modern browser (and has been for decades).
Deprecated / legacy.
Do not use Internet Explorer conditional comments (<!--[if IE]>). Do not wrap <script> bodies in HTML comments — that old habit is obsolete; use JavaScript comments instead.
Not an HTML element.
A comment is not a DOM element you style or script. Prefer View Source or DevTools to inspect it.
Syntax
HTML Syntax
syntax.html
<!--comment text -->
Start with <!-- and end with -->. Single-line and multi-line forms use the same delimiters. Comments are only allowed as content (between tags) — not inside a start tag before attributes.
Do not nest comments; the first --> closes the comment.
Comment text must not start with > or ->, must not contain --> or --!>, and must not end with <!- (HTML living standard).
Inside <script> and <style>, use language comments (//, /* */), not HTML comments.
Reference
Attributes
HTML comments are not an element, so they have no attributes.
Item
Description
Try it
<!-- -->
Only valid form — start delimiter, optional text, end delimiter
Section comments help teammates scan the source file.
How It Works
Add a label comment above each major region.
Keep labels short (Header, Main, Footer).
Write the real elements after each comment.
Browse the page. Only <header> and <main> content shows.
Example 4 — Rules and Common Mistakes
Valid syntax, no nesting, and never store secrets in comments.
HTML
<!-- Valid: short source note -->
<!-- Valid multi-line comment
that spans several lines -->
<!-- WRONG ideas (do not do these):
- invent a <comment> element
- nest <!-- inside another comment
- store API keys or passwords here
-->
<p>Only this paragraph is visible.</p>
Treat comments as public. View Source shows them to everyone.
Prefer short notes. Long commented-out blocks belong in version control history once you are done debugging.
Edge Cases & Pitfalls
Most comment bugs come from nesting, wrong placement, or treating source notes as private.
security
Comments are public
View Source and DevTools show every comment. Never store secrets there.
syntax
No nesting
The first --> closes the comment. Nested <!-- breaks the following markup.
placement
Not inside a start tag
Comments are content only. Do not put them between a tag name and its attributes.
raw text
Avoid in script / style / title / textarea
Those elements treat content as raw text. Use JS/CSS comments inside <script> and <style>.
legacy
IE conditional comments are gone
<!--[if IE]> was a non-standard IE feature. Do not use it in modern pages.
Compatibility
Browser Support
HTML comments are core HTML syntax in every browser. They are not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<!-- -->
Supported everywhere for decades. Chrome, Firefox, Safari, Edge, and Opera all ignore comments when rendering and keep them in the source.
100%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Supported
<!-- -->Widely supported
Bottom line: Safe to use everywhere for documentation and temporary disable. Treat comments as public text in the delivered HTML.
Remember
Key Takeaways
Syntax: only <!-- … --> — there is no <comment> tag.
Visibility: hidden on the page, visible in View Source.
Uses: document sections, label regions, or comment out markup while debugging.
Rules: no nesting, no secrets, no HTML comments inside script/style bodies.
One line:<!-- --> is for developers reading the source — never for hiding private data.
UA style
Default CSS Settings
Comments do not create boxes in the page, so user-agent stylesheets do not style them. There is no default CSS to override.
default.css
/* HTML comments are not rendered nodes.
No user-agent CSS applies. */
To hide visible content for users, use CSS or remove the markup — do not rely on comments as a UI feature.
Frequently Asked Questions
No. HTML comments use the <!-- comment text --> syntax. There is no <comment> element in the HTML specification.
No. Browsers ignore comments when rendering. They remain only in the HTML source (View Source or DevTools).
No. Anyone can read comments via View Source or developer tools. Never put passwords, API keys, or private data in comments.
No. The first --> closes the comment. Nested <!-- inside a comment is invalid and breaks the markup.
Only as content between tags — not inside a start tag before attributes. Avoid HTML comments inside title, textarea, script, and style; those treat content as raw text. Prefer // or /* */ inside script and style.
Developers use them to document markup, label sections, and temporarily disable HTML blocks while debugging — without deleting the code.
Welcome! Please log in to continue.