How to write comments in a Markdown File

featured Image

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

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *