How to write comments in a Markdown File

In this post, we will see how to write comments in a markdown file.

Comments are helpful to explain certain parts of code or text in a document. And if you are using markdown as a medium to create web pages using any markdown parser then you might not want to display the comments in your HTML output.

Markdown doesn’t have any default syntax to write comments in a document. However, there are different workaround to this problem.

Add Comments in Markdown

Here, are a few examples to comment on your markdown document.

To comment we can use this.

[//]: <> (this is a comment)

or we can use a # instead of <>.

Note: If you want to comment in README.md of github, then use #, because github rejects <>.

[//]: # (this is a comment)

You can write whatever you want inside [//] instead of the double forward slash. The output will be the same.

[whatever]: # "And this is a comment"

And another way to comment in markdown is like this

[this is comment]::

IMPORTANT: Keep a blank line before you write a comment in the markdown.

❌ Wrong way to add comments

Markdown is a lightweight markup language
[//]: # (this is comment)

✔️ Correct way to comment in markdown

Markdown is a lightweight markup language

[//]: # (this is comment)

Always leave a blank line before the comment.

Note: The above metioned ways DO NOT allow multiline comments and so if you have multiline comments, then you have to add the comment syntax in each line.

To add multiline comments in your markdown, you can use the HTML comment syntax.

Add HTML comments in Markdown

Since markdown also supports plain HTML tags, we can use the HTML comment syntax too. These comments will not be displayed in your HTML output.

<!-- this is HTML comment -->

<!--- this is multiple
comment in markdown --->

We can use both <!-- (double dashes) or <!--- (triple dashes ) HTML comment in markdown. However, it is recommended to use the <!--- triple dashes because it is compatible with most markdown compilers.


Related Articles:

How to write superscript and subscript in markdown

How to center align an image in markdown

How to do text highlight in markdown

How to underline in markdown

How to change image size in markdown in GitHub

How to make horizontal line in markdown

Easy Way to add Emoji in markdown with VS Code

Scroll to Top