Comment out a block
An HTML comment can cover many lines, including Markdown you want to hide for now without deleting it.
You write
Visible.
<!--
## A section not ready yet
- Draft point one
- Draft point two
-->
Also visible.You see
Visible.
Also visible.
The [//]: # trick
A link definition with no link using it is never shown, so some people write comments as one. It works in most apps, but only for a single line, and the text must sit inside the brackets.
You write
[//]: # (This line is hidden too.)
Visible text.You see
Visible text.
The HTML comment is clearer and more widely understood, so use it unless an app removes HTML.
Comments are not secret
A comment is hidden on the page, but it is still in the file. Anyone who opens the file, or views the source of a web page made from it, can read it. Never put passwords or private notes in a comment.
Where comments are hidden
| App | <!-- --> | [//]: # |
|---|---|---|
| GitHub | Hidden | Hidden |
| MarkdownPaper | Hidden | Hidden |
| Apps without HTML | May show | Hidden |
Common problems
- The comment shows on the page. The closing
-->is missing or mistyped. Everything after an unclosed comment can vanish too, so check for it first. - A comment inside code shows. That is expected: code blocks show everything as typed.
Questions
What is the syntax for a comment in Markdown?
<!-- comment -->. It is HTML, and Markdown apps that allow HTML hide it.
How do I comment out a line in Markdown?
Wrap it in <!-- and -->. For a single line you can also write
[//]: # (the line).
Do comments work in GitHub README files?
Yes. GitHub hides HTML comments in README files, issues and comments.
Next
- Collapsible sections, for text that should stay on the page but out of the way.
- Check what your file shows before you share it.