How to write a comment in Markdown:an HTML comment hides the text.
Markdown has no comment syntax of its own. You borrow the one from HTML, and the text stays in the file but out of the rendered page.
macOS 14 or later. Reading is free; editing and reviews are one payment.
Quick answer
A Markdown comment is an HTML comment: put the text between <!-- and -->. It is not shown in the rendered page, it can run over several lines, and it stays in the file, so anyone who opens the raw text can read it.
<!-- This text is hidden -->
<!--
A longer note
on several lines
-->
·
Comment syntax in Markdown
Markdown itself has no comment. It does allow raw HTML, and HTML has comments. CommonMark treats a line that starts with <!-- as the start of an HTML block, and the block ends at the first line that contains -->. The whole block passes through as HTML, and the browser does not draw it.
That gives you a single-line comment and a multi-line comment with the same syntax. A multi-line comment is just a comment whose closing --> is on a later line.
Some text.
<!-- A note to myself -->
More text.
The rendered page shows:
Some text.
More text.
A comment inside a paragraph
A comment can also sit in the middle of a line. In that case it is inline raw HTML, and it is hidden in the same way.
The launch is on Friday <!-- check the date with Sam --> for everyone.
The launch is on Friday for everyone.
A comment that starts at the beginning of a line is a block. The rest of its last line, after -->, belongs to the same block, so keep text off the closing line.
Comment out a block of Markdown
To switch off a section for now, wrap it. Headings, lists and paragraphs inside the comment are not rendered.
<!--
## Old section
- first point
- second point
-->
The comment ends at the first -->. If the block you are hiding already contains a comment, the outer one closes early and the rest shows up on the page. Remove the inner comment first.
A comment also works between two lists. Because it is a block, it ends the first list, so the two lists render as separate lists. The CommonMark spec uses this to split lists.
The [//]: # workaround
You will see comments written as link reference definitions:
[//]: # (This is a comment)
This is a workaround, not a comment. It is a link reference definition with the label // and the title in parentheses. Nothing links to it, so nothing is rendered. It needs a blank line before it, because a link reference definition cannot interrupt a paragraph. It works in tools that follow CommonMark, but the text is not marked as a comment, and an HTML comment is clearer.
Comments in code blocks are shown
Inside a fenced code block or a code span, <!-- --> is just text. It is displayed, not hidden. That is why this page can show the syntax. Write a comment outside the code block, or use the comment syntax of the language inside it.
Notes in CLAUDE.md and AGENTS.md
According to the Claude Code documentation, block-level HTML comments in a CLAUDE.md file are removed before the content is given to Claude. They are meant for notes to human maintainers, and they do not use context tokens. Comments inside code blocks are kept. If you open the file directly with the Read tool, the comments are visible.
The same page does not say how other tools treat comments in an AGENTS.md file, so check your tool before you rely on it. For a note that an agent must read, write it as normal text.
Mistakes that break a comment
- No closing
-->. A comment that starts a line runs to the end of the document or of its container, and everything after it disappears. - A
-->inside the comment. It ends the comment there, and the rest of the text is shown. - Double hyphens in the text. The current CommonMark spec allows them, but XML does not, so an XML-based tool may reject the file. Use a single hyphen or a different word.
- A comment in a list item. Indent it to line up with the item's text. At the margin it ends the list.
- Text after
-->on the closing line. In a block comment that text is part of the HTML block, so it is not rendered as Markdown.
The quickest check is to open the file in a reader. DotMD shows the rendered page, so a comment you wrote does not appear in it. Reading is free.
A comment that should not live in the file
An HTML comment is part of the document. A note for a reviewer or an AI agent often should not be. In DotMD you select a passage and leave a comment that is kept by the app, outside the file. The Markdown stays clean. Comments are part of DotMD Reviewer. The Comments guide shows how.
Questions about comments in Markdown
How do I write a comment in a Markdown file?
Put the text between <!-- and -->. It is not shown in the rendered page.
How do I write a multiline comment in Markdown?
Open with <!-- at the start of a line, write as many lines as you need, and close with -->. The comment ends at the first line that contains -->.
Is a Markdown comment really hidden?
Only from the rendered view. The text stays in the file, and it can stay in the page's HTML source. Do not store secrets in it.
Does a Markdown comment work on GitHub?
Yes. An HTML comment is hidden in the rendered Markdown of a README, an issue or a pull request.