An HTML comment adds explanatory notes to your markup or prevents the browser from interpreting specific parts of the document. Comments start with <!-- and end with -->. They are not rendered as page content.
What are comments for in an HTML tutorial?
Label sections for teammates, leave TODOs, or temporarily disable a block while debugging—without deleting the code. The browser skips the comment; View Source still shows it.
Where can you place comments?
As content between tags (in <head>, <body>, inside most elements). You cannot put a comment inside a start tag (for example before an attribute). Avoid HTML comments as the content of raw-text elements like <script>, <style>, <title>, and <textarea>—use JS or CSS comment syntax there instead.
When should you use them?
Document non-obvious structure, mark regions in large templates, or comment out experimental markup. Keep notes short; never store secrets in comments.
Not an HTML element.
A comment is a special construct in the HTML syntax—not a tag you open and close like <p>.
Comments cannot nest.
The first --> ends the comment. Nested <!-- breaks parsing and can spill markup onto the page.
Visible in source.
Anyone can open View Source or DevTools and read your comments. Treat them as public notes.
Syntax
HTML Comment Syntax
The basic form:
comment.html
<!--Comment text -->
HTML
<!-- A one-line comment -->
<!--
A comment
that stretches
over several
lines
-->
<!-- Disables the HTML contained within -->
<!--
<p>This content will not be rendered.</p>
-->
Empty comments are allowed: <!--> or <!---->. Comment text must not start with > or ->, must not contain --> or --!>, and must not end with <!-.
Reference
Core HTML Concepts
Rules that keep comments valid and useful:
Concept
Meaning
<!-- … -->
Opens and closes an HTML comment
Not rendered
Browser skips comment content when painting the page
Document / disable
Notes for developers, or wrap markup to turn it off
Content only
Between tags—not inside a tag’s attribute list
No nesting
First --> closes the comment
Raw-text elements
Prefer JS/CSS comments in script / style (and avoid HTML comments in title / textarea)
View Source
Comments remain in the delivered HTML file
Comment vs element
HTML comment
HTML element (e.g. <p>)
Visible on page?
No
Usually yes
In DOM as a node?
Comment node (tools can see it)
Element node
Attributes?
No
Yes
Approach
How to Use Comments in HTML
Practical habits for clean markup.
Write <!-- note --> next to the markup it explains.
Explain why, not what every obvious tag does.
To disable a block, wrap it in one comment—do not nest comments.
Label major regions (<!-- Site header -->) in large templates.
Remove obsolete comments when the code changes.
Never put passwords, tokens, or private customer data in comments.
Goal
Pattern
One-line note
<!-- Primary stylesheet -->
Multi-line note
<!-- … several lines … -->
Disable markup
<!-- <p>…</p> -->
Script notes
// or /* */ inside <script>
CSS notes
/* … */ inside <style> or a stylesheet
Try it
Live Preview
Toggle whether a paragraph is commented out and see what the browser renders.
Shows rendered output vs source shape. Comments never appear as page text.
Rendered page
Comments demo
This paragraph is visible on the page.
<!-- This note is for developers only -->
<p>This paragraph is visible on the page.</p>
Code
HTML Examples
Six patterns: basic syntax, commenting out markup, multi-line notes, inline TODOs, head notes, and a full page.
Example 1 — Basic Comment Syntax
HTML
<h1>Comments demo</h1>
<!-- This note is for developers only -->
<p>This paragraph is visible on the page.</p>
Source still includes every comment for developers.
Edge Cases & Pitfalls
Broken pages often come from nested comments or forbidden strings inside the comment body.
nest
Nested comments
The first --> closes the comment. Leftover text can become live HTML.
inside
Comment inside a start tag
Invalid. Place comments between elements, not among attributes.
script
HTML comments wrapping entire scripts
Legacy practice for ancient browsers. Do not rely on it—use proper JS comments.
secrets
Secrets in comments
View Source exposes them. Use environment config, not HTML comments.
strings
Forbidden sequences in the body
Avoid starting with > / ->, containing --> / --!>, or ending with <!-.
bloat
Huge comment blocks in production
They increase download size slightly and clutter source. Prefer short, useful notes.
Compatibility
Browser Support
HTML comments () are part of the HTML language and work in all browsers.
✓ Baseline · Widely available
HTML comments
Every browser that parses HTML understands comments and skips them when rendering.
100%comment syntax
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
HTML commentsUniversal
Bottom line: Use freely for developer notes—just remember they ship with your HTML source.
Remember
Key Takeaways
<!-- … --> documents or disables markup without showing on the page.
Cannot nest and cannot sit inside a start tag.
View Source still shows comments—no secrets.
script/style use language comments, not HTML comments.
One line: Write <!-- notes or disabled HTML --> between tags so the browser skips it while teammates can still read the source.
Frequently Asked Questions
An HTML comment adds notes to your markup or hides markup from the browser. It starts with <!-- and ends with -->. The browser does not render comment content on the page.
Use <!-- your note here -->. For several lines, keep text between the same opening and closing delimiters. Do not put --> inside the comment body.
Not on the rendered page, but comments appear in View Source, DevTools, and downloaded HTML. Never put secrets, API keys, or private data in comments.
Wrap the markup in <!-- and -->. The browser skips that block. Remove the delimiters when you want the markup active again. Comments cannot nest.
No. Comments are only allowed as content—between tags—not inside a start tag before attributes.
No for modern code. Use JavaScript // or /* */ and CSS /* */. title, textarea, script, and style treat their contents as raw text, so HTML comments are not appropriate there.