Skip to content

Instantly share code, notes, and snippets.

@jonikarppinen
Last active April 21, 2024 23:44
Show Gist options
  • Star 62 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jonikarppinen/47dc8c1d7ab7e911f4c9 to your computer and use it in GitHub Desktop.
Save jonikarppinen/47dc8c1d7ab7e911f4c9 to your computer and use it in GitHub Desktop.
How to comment out stuff in Markdown on GitHub?

Comments in GitHub flavour of Markdown

As answers to this Stack Overflow question reveal, using <!--- and ---> or <!-- and --> works (view source by clicking "Raw"):

Inline comments

How about commenting out <!--- just ---> a part of one line?

If you know of a way, please show me how by cloning this Gist, or commenting below!

Update 2019

As several commenters pointed out, for inline commenting <!-- a normal html comment --> now works.

You can't see this:

Btw, wow, I created this gist in 2014 and only now became aware of the discussion and that it's the top Google hit for markdown comments github. 👍

@thefzsalam
Copy link

thefzsalam commented May 30, 2017

I can still see the in the second paragraph. EDIT: I accidentally figured out that using two '-' hyphens like ` - see raw. But this doesn't work <!--- This isn't commented out --->.
2017-05-30-175951_928x249_scrot
2017-05-30-180001_1017x294_scrot

@utkarsh2102
Copy link

utkarsh2102 commented Jun 27, 2018

Check?

P.S. <!--- --> is working :)

@kerimeredith
Copy link

kerimeredith commented Sep 7, 2018

https://github.github.com/gfm/ has this:
"An HTML comment consists of <!-- + text + -->, where text does not start with > or ->, does not end with -, and does not contain --. (See the HTML5 spec.)"

I had a URL that I wanted to comment out but could not figure out how to do that. (http://foo-bar.s3-website-us-bla-1.amazonaws.com/#)

@ianrodrigues
Copy link

ianrodrigues commented Sep 11, 2018

@element6
Copy link

element6 commented Nov 9, 2018

You can't see this:

nor this:

@Simonkyverde88
Copy link

I believe a comment is written <!--Text--> and not <!---Text--->. The second will just cause trouble and obvious errors.

@jonikarppinen
Copy link
Author

Idea for triple dash came from https://stackoverflow.com/a/4829998. Back when this gist was originally written, the normal html comment didn't work at least for inline comments.

Anyway, gist updated now, thanks for all the comments! 😏

@matb33
Copy link

matb33 commented Jan 25, 2020

Note that GitHub's search won't index what's in these comments.

@kublermdk
Copy link

kublermdk commented Feb 11, 2020

I thought for a moment that comments are now shown, but I just checked and they aren't.

There's two comments above, in double and triple hyphens and you shouldn't be able to see them.

@rowe-morehouse
Copy link

rowe-morehouse commented Sep 11, 2020

Try this:

[//]: # (This is a comment.)
[//]: # (This is a comment on a new line.)

Make sure add a double space after each comment line.

@DamieFC
Copy link

DamieFC commented Dec 29, 2020

Thanks for putting this up!

@hilbix
Copy link

hilbix commented Mar 5, 2021

Try this:

[//]: # (This is a comment.)
[//]: # (This is a comment on a new line.)

Make sure add a double space after each comment line.

@rowe-morehouse Genius!

@DamieFC
Copy link

DamieFC commented Mar 5, 2021

@hilbix Ik right?

@mahtamun-hoque-fahim
Copy link

Thank you so much @Simonkyverde88 and @rowe-morehouse ❕ :
I've tried both of your tricks , Both worked properly!
Thank you again ! 😌

@insyri
Copy link

insyri commented May 16, 2021

More visual example for n00bz.

image

@martinamorris
Copy link

Is it possible to comment out lines that have code embedded? I have some lines like:

You will then need to: library(statnet)

And when commented like this:

[//]: # (You will then need to: library(statnet))

I am getting this:

image

Thanks!

@SiddharthShyniben
Copy link

Now you see me ​​

Screen Shot 2021-07-14 at 9 21 56 AM

Neat, huh? Only the URL has to be properly formatted. so we get https://now-you-don't

Here's another

Screen Shot 2021-07-14 at 9 25 01 AM
This might be really useful, for something like comment footnotes:

@rinogo
Copy link

rinogo commented Oct 19, 2021

Thanks for this! Also, regarding your surprise about being the top Google hit:
Google is weird. Surely, no one is linking to this gist, but Google still considers it authoritative. Google is weird.

@kasperosterbye
Copy link

I do not understand why, but it seems like <? and ?> can be used for comments, both multiline and single line. Anyone knows why?

@SiddharthShyniben
Copy link

@kasperosterbye Nice find! I'm guessing it has something to do with PHP or XML?

@thewhitegrizzli
Copy link

@kasperosterbye nice thanks what i was actually looking for

@thewhitegrizzli
Copy link

@kasperosterbye and I have no clue why I don't rly care hahahahha thks! cheers

@benkoshy
Copy link

<!---
your comment goes here
and here
-->

Cutting and pasting the SO answer, for easy reference.

@kolakode
Copy link

For whole line and multiline comments, this tweak of Rowe's suggestion appears to work for mdcat, VS Code, Gist preview, and online markdown editors I've tried:

[this is a one line comment]: #
   [  it's ok to have 1, 2, or 3 leading spaces  ]: #
but anything else before [ or ]: # after would unhide the comment
as would indenting it 4 or more spaces.

[
this is a
    multiline
comment
]: #

[   as is this compact version
    with no space between `:` and `#`
]:#

  [
    it too can have the `[`
    indented up to 3 spaces
        other line can be indented more
  ]: #

Indenting the [ bracket of the comment 4 or more spaces will make the line be rendered as a pre-formatted block and make the comment visible. Personally, I like the compact version better than the <!-- ... --> for multiline comments, but this trick isn't supported by most syntax highlighters.

@amenity
Copy link

amenity commented Sep 6, 2022

Thank you so much @jonikarppinen 🤗 !! Here's hoping Github (along w/ Slack & Zenhub, plz) make their markdown more standard/vanilla/usable so we can all be productive at work.

<!--cc/ @jonikarppinen, in case your two Github handles are not the same. :upside_down_face: -->

@A-Kiwams
Copy link

A-Kiwams commented Sep 7, 2022

Works simple

@GoelDarpan
Copy link

GoelDarpan commented Oct 9, 2023

Need help - dotnet/docfx#9285

@sienna-jeong
Copy link

Is there a keyboard shortcut to do it?

@wxnnvs
Copy link

wxnnvs commented Feb 27, 2024

@a-pav
Copy link

a-pav commented Apr 18, 2024

I just used this trick in a comment where I thought some details I've wrote might be unnecessary but at the same time I didn't want lose those details, and, I might actually need those in a follow up comment. So I commented them out, now I have access to those by pressing Edit mwahahaha :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment