Live Preview
Only the paragraph below renders. The comment above it exists in source code only:
This text is visible on the page.
(A comment sits above this in the HTML source but is not shown here.)

By the end of this tutorial, you’ll write HTML comments with the correct <!-- --> syntax and avoid common beginner mistakes.
Use <!-- -->—there is no <comment> element.
Browsers ignore comments when rendering the page.
Leave notes for yourself and teammates in the source.
Temporarily disable HTML blocks without deleting code.
Never store passwords or API keys in comments.
Learn nesting limits and common mistakes to avoid.
HTML comments are notes in your source code that browsers do not display on the page. They use the <!-- --> syntax—there is no <comment> HTML element.
Comments are markup syntax, not a tag like <p> or <div>. Always write <!-- Your comment here -->—never <comment>...</comment>.
A comment is text in the HTML source that is ignored by the browser when rendering. It helps developers explain code, mark sections, or temporarily disable markup.
Single-line and multi-line comments use the same delimiters:
<!-- Single-line comment -->
<!--
Multi-line comment
spanning several lines
--><!-- and end with -->.--> closes the comment.| Feature | Syntax / Rule | Notes |
|---|---|---|
| Start delimiter | <!-- | Begins every comment |
| End delimiter | --> | Closes the comment |
| HTML element? | No | Markup syntax only |
| Visible on page? | No | Hidden from rendered output |
| Nesting | Not allowed | Cannot comment inside a comment |
| Security | Public in source | Anyone can read via View Source |
HTML comments are not an element, so they have no attributes:
class N/AComments cannot have a class—they are not DOM nodes.
Not applicableid N/AComments cannot be targeted with CSS or JavaScript by id.
Not applicableSyntax RequiredOnly valid form: <!-- comment text -->
<!-- -->Multi-line AllowedSame delimiters work across multiple lines.
<!-- ... -->Nesting ForbiddenCannot put <!-- inside another comment.
InvalidVisibility Source onlyVisible in View Source and DevTools, not on the page.
PublicComments are for developers reading the HTML file—not for styling or scripting.
Documentation, debugging, section labels, and syntax rules with copy-ready code and live previews.
Only the paragraph below renders. The comment above it exists in source code only:
This text is visible on the page.
(A comment sits above this in the HTML source but is not shown here.)
Leave a short note explaining what a section does.
<!-- This section handles the login message -->
<p>Welcome! Please log in to continue.</p>Developers use HTML comments to document sections, label layout regions, temporarily disable markup while debugging, and leave notes for teammates.
Wrap markup in a comment to disable it without deleting the code.
<!--
<div class="debug-box">
Temporarily disabled block
</div>
-->
<p>Only this paragraph renders.</p>Use comments as signposts in large HTML files.
<!-- ===== Header Section ===== -->
<header>...</header>
<!-- ===== Main Content Section ===== -->
<main>...</main>Know what is valid and what to avoid as a beginner.
<!-- Valid comment -->
<!-- WRONG: no <comment> element exists -->
<!-- WRONG: do not store API keys or passwords here -->Comments are not styled with CSS on the page—they never render. In editors and syntax highlighters, comment text is usually shown in a muted color so you can distinguish notes from active markup:
<!-- Opening delimiter--> Closing delimiterView Source Visible in HTML fileNot in DOM Skipped when rendering<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta tags and title go here -->
<title>My Page</title>
</head>
<body>
<!-- ===== Hero Section ===== -->
<section class="hero">
<h1>Welcome</h1>
</section>
</body>
</html>What users see vs. what developers read
Rendered page: only the heading “Welcome” appears.
HTML source: comments remain visible between delimiters for developers.
HTML comments are visible to anyone via View Source or browser DevTools. Never store passwords, API keys, tokens, or sensitive data in comments.
Comments are invisible to users and assistive technologies:
Text between <!-- and --> in the HTML file.
Comments are ignored during page rendering.
Still visible in View Source and developer tools.
Notes for developers without affecting what users see on the page.
All browsers ignore HTML comments when rendering pages. Comments are a universal part of HTML syntax, not a feature that varies by browser.
From legacy Internet Explorer to the latest mobile browsers — every engine skips comment nodes during rendering.
Bottom line: Use <!-- --> with confidence. Every browser ignores comments during rendering while keeping them in the source for developers.
HTML comments use <!-- --> syntax to add developer notes that browsers do not display. They help you document code, organize structure, and debug—but they are not an HTML element, cannot be nested, and must never contain secrets.
<!-- --> for all comments<comment> tagBookmark these before you ship — they’ll keep your source clean and secure.
Use <!-- text --> — not a tag element.
There is no HTML comment element in the spec.
EssentialBrowsers skip comments when rendering the page.
BehaviorView Source and DevTools still show comment text.
VisibilityThe first --> closes the comment block.
Great for notes, section labels, and comment-out debugging.
Pattern<!-- --> syntax. There is no <comment> element in HTML.--> closes the comment, which breaks nested attempts.Practice the correct <!-- --> syntax in the interactive HTML editor.
6 people found this page helpful
⚖️ Comments vs HTML Elements
Comments are fundamentally different from HTML tags:
<!-- text --><tag>...</tag><!-- Header --><p>Hello</p>