To comment in HTML, write your note between <!-- and -->. A comment can fit on one line or span several lines. Its text is not displayed as ordinary page content, but anyone who receives the HTML can inspect it. Keep passwords, private notes and other secrets out of comments.
You can use comments to explain a decision, mark a section for another editor or temporarily remove a small piece of markup from the rendered page. They are most useful when they answer a question the code does not answer for itself. This guide shows the syntax, a complete example and the mistakes that can make a comment behave unexpectedly.

How to comment in HTML: the basic syntax
Start with a less-than sign, an exclamation mark and two hyphens. Finish with two hyphens and a greater-than sign. The closing marker has no exclamation mark. Put the explanation between those markers rather than inventing a closing comment tag.
<!-- Explain why this section exists. -->
<p>This paragraph is visible.</p>
Only the paragraph appears as visible page text. The note is still part of the document source. If you are new to the language itself, our explanation of what HTML stands for explains how markup gives content structure.
Purdue’s HTML teaching guide demonstrates the same comment notation. That older guide is useful here for this basic syntax; treat unrelated historical markup examples as historical rather than copying an entire old page as a modern template.
Good spacing makes it easy to read through the source. Adding spaces around the note does not make it visible on the page. Make your comments useful. For example, if there are a few lines of code in an unusual order, describe why this was done. Do not repeat the name of the heading below the line. This will be helpful when someone else has to edit your file.
Write a comment across several lines
The same markers work for multiline notes. There is no separate multiline HTML comment command. Add line breaks inside the comment to keep a longer explanation readable, and close it before the content that should appear normally.
<!--
The seasonal notice is awaiting approval.
Restore this section when the dates are confirmed.
-->
<p>The regular opening hours are unchanged.</p>
When writing this note keep it concise. The conditions for revisiting that particular decision and the area(s) of the code impacted by your revision will likely be far more helpful than a full history of all changes made prior. If you are documenting a process or an event (i.e., something your team may need to revisit in the future), provide your team with a mechanism to locate and address that task.
Do not leave a misleading comment behind after changing the code it explains. A perfectly valid comment can still waste time if it says a feature is disabled when that feature has already been restored. Review nearby notes whenever you edit the associated markup.
Comment out a small block of markup
Wrapping a simple block in a comment can temporarily keep that block from rendering. Inspect the entire selection first. This technique is unsuitable when the selected block already contains comments, and it should not replace version control for material you intend to remove permanently.
<p>Available today: guided tours.</p>
<!--
<section class="seasonal-notice">
<h2>Winter opening hours</h2>
<p>The new timetable will appear here.</p>
</section>
-->
<p>Contact reception for current opening times.</p>
The first and last paragraphs remain visible. The seasonal section between them is contained inside the comment. When you restore it, remove the outer comment markers and check the page again. Keep a real copy of the working file so an experimental change is easy to reverse.
Brown University’s introductory HTML lab describes using comments to annotate code and help locate problems. Use that approach on a small section at a time. If you disable several unrelated parts together, you lose the ability to tell which change affected the result.

Try a complete commented HTML page
Save this document as comments.html in a plain-text editor and open it in a browser. The title, opening hours and shoe advice are ordinary content. The comments explain an editorial choice and an outstanding task. Neither comment needs to appear in the visitor’s reading copy.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Community garden opening times</title>
</head>
<body>
<main>
<h1>Community garden</h1>
<!-- Keep opening times near the title for returning visitors. -->
<p>Open Saturday, 10:00 to 16:00.</p>
<!--
Volunteer notice paused until the coordinator confirms details.
This is an editorial note, not private information.
-->
<p>Bring suitable shoes for the paths.</p>
</main>
</body>
</html>
After opening the file, inspect its source and find both notes. Next, change the opening-hours paragraph, save and reload. Notice that the paragraph changes while the comments stay out of the visible copy. This gives you a small, understandable file for learning before you experiment inside a larger website.
The standalone document contains its own main heading. If you are editing a WordPress article, the theme normally supplies the post-title heading instead. Do not paste the entire document skeleton into the middle of an existing article. Choose the editing area appropriate to the content you are changing.
Know where comments belong and why nesting fails
Place a comment between pieces of markup, not in the middle of a start tag or between an attribute name and its value. A comment is not an attribute. Splitting a tag with comment markers can leave the parser reading something very different from what you intended.
Comments also do not nest. Adding another opening marker inside an existing comment does not create an independent inner comment. An inner closing marker can terminate the outer comment sooner than expected, leaving following text or markup outside it. Before wrapping a section, search that selection for existing markers.
For ordinary notes, avoid comment-marker strings inside the note itself. The HTML syntax has specific restrictions on how comment text starts, ends and contains delimiter-like sequences. Use straightforward words rather than experimenting with combinations that depend on error recovery. HTML and XML comment restrictions are not identical, so do not assume an HTML example covers an XML document too.
| Mistake | What goes wrong | Safer approach |
|---|---|---|
| Missing closing marker | Later markup may become part of the comment | Close the note before visible content |
| Comment inside a start tag | Invalid markup changes parsing | Move the note before the element |
| Wrapping existing comments | The closing boundary becomes ambiguous to the author | Remove a small block or use version control |
| Private information in a note | The delivered source can disclose it | Keep private data out of the document |
Use the right comment syntax for each language
An HTML document can contain CSS and JavaScript, but they still have their own syntax. Inside a style element, use a CSS comment. Inside a script element, use JavaScript comments. Do not paste HTML comment markers into either language as a general commenting technique.
<style>
/* Keep the reading column comfortable. */
main { max-width: 42rem; margin-inline: auto; }
</style>
<script>
// Record a demonstration value.
const places = 12;
/* A block comment can occupy several lines. */
console.log(places);
</script>
Princeton’s introductory JavaScript lab explains line comments introduced by two forward slashes. The practical distinction is the language context: a slash-based note belongs in JavaScript, while an HTML note uses the markup comment markers. Our guide to HTML’s role as a markup language gives the wider context.
Some older pages wrap script content in HTML comment markers for compatibility with very old browsers. Do not copy that legacy pattern into a new example. Comment the JavaScript as JavaScript and keep the surrounding document markup separate from the program.
Use an editor command without guessing the syntax
Many code editors provide a Toggle Comment function. Highlight your intended comment or entire markup section. Check that you are editing with an HTML file. Use the editor’s Toggle Comment (or similar) function. Once you do so, examine the characters that were added. While shortcuts can be helpful, they should ultimately produce valid characters for the selected programming language and selection.
If the editor inserts slash-style comments where you expected HTML markers, check the active language mode and whether your cursor is inside a script or style region. Different editors and keymaps can assign different shortcuts, so use the command menu or keybinding settings to find the action rather than assuming one key combination works everywhere.
Undo the operation if it creates a nested-comment problem. Do not repeatedly toggle a mixed selection and hope the editor can infer which existing markers should count as the outer boundary.
An HTML comment is not a privacy feature
Not appearing on the rendered page is different from not being delivered. A comment can remain in the HTML response, in a downloaded file or in an inspected document. A visitor does not need access to your editor to read a comment that your server sent to their browser.
Use fictional details when creating example scenarios. Never include an actual password, access token, or a customer’s private detail as part of a comment thinking you have blocked it from view. If confidential data is delivered accidentally, editing the comment alone does not address the disclosure.
Build tools and content-management systems may remove comments, preserve them or interpret particular comment patterns. Inspect the actual output you deliver. Do not rely on a minifier to rescue confidential information that should never have entered public markup in the first place.
Use a short debugging checklist
If a comment appears on the page or a section disappears unexpectedly, start with the exact characters around its boundaries. Look for a missing hyphen, a missing greater-than sign, an extra exclamation mark or a closing marker inside a block you thought was disabled.
- Reduce the problem to one note and one visible paragraph.
- Check whether you are editing HTML, CSS, JavaScript or a template.
- Restore a complete, balanced block rather than half an element.
- Compare the editor’s content with the delivered source.
- Validate the markup and inspect the surrounding structure.
Comments in templates or editors may also carry specific meanings to the application. An example is how WordPress blocks are serialized using structured comment markers. Don’t delete those markers simply because you could safely delete them as ordinary HTML comments. Instead work with the editor to make sure you’ve gone through all of its native block control options before making that structural modification.

FAQs and a quick self-check
Can I make a one-line HTML comment?
Yes. Put the opening marker, a short note and the closing marker on the same line. Multiline comments use exactly the same boundaries.
How do I show comment markers as visible text?
Encode the angle brackets as HTML character references. That displays the example rather than asking the HTML parser to interpret it as an actual comment.
<p>The comment starts with <!-- and ends with -->.</p>
Do comments provide a place for visitor replies?
No. Source-code comments are notes in markup. A public discussion area needs a separate comment form, storage and moderation process.
Self-check: is a password safe inside an HTML comment?
No. The comment may be readable in delivered source even when it is absent from the rendered page.
Self-check: can an outer HTML comment safely wrap a block containing another comment?
No. HTML comments do not nest. Inspect the selection and use a different temporary-editing approach.