Comment syntax
Starts with <!-- and ends with -->. Everything between them is treated as comment text.
Learn HTML Comments as a practical HTML text lesson with syntax, examples, common mistakes, accessibility notes and a live code lab.
HTML text basics
An HTML comment starts with <!-- and ends with -->. The browser reads it as a comment node, but it does not display it as visible page content.
Comments are useful for short developer notes, template boundaries and temporary explanations during development. They are not private.
Anything inside an HTML comment can still be visible in view source, browser DevTools, caches or deployed files. Never put passwords, tokens or secrets in comments.
Starts with <!-- and ends with -->. Everything between them is treated as comment text.
The comment is not rendered as visible content in the page.
Anyone can inspect frontend source code. Comments are not security.
Short section markers can help large templates stay readable.
Syntax and meaning
Use comments when they explain why something exists. Avoid comments that merely repeat obvious markup.
<!-- Pricing cards are generated from CMS data. Keep card order stable for tracking. -->
<section class="pricing-grid">
<article>
<h2>Starter</h2>
<p>For small projects.</p>
</article>
</section>
<!-- password: admin123 --> <!-- This is a heading --> <h1>HTML Comments</h1> <!-- This is a paragraph --> <p>Comments should add useful context.</p>
Practical rules
These rules are the part that saves time in real projects. If the HTML meaning is clean, CSS, JavaScript, accessibility checks and search optimization become easier to reason about.
Frontend comments are visible to anyone who inspects the page source.
Good comments explain intent, constraints or template behavior.
Do not leave large commented-out blocks in production templates.
Long explanations belong in documentation unless they must live next to the markup.
Avoid putting -- inside comments because it can create invalid or confusing markup.
Some build tools preserve comments and some strip them. Know your pipeline.
Production thinking
Text markup matters because browsers and assistive technology do not only see letters. They also read structure, emphasis, quotes, code and relationships between pieces of text.
Comments are not announced as content, so they cannot replace visible instructions, labels or help text.
Before deployment, scan comments for TODOs, internal URLs, test credentials and old debugging notes.
Search engines generally do not treat comments as visible content. Do not hide keywords in comments.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.