This might appear silly, but I have been wondering for a while, how can I put code inside a comment in stackoverflow. I haven't been able to figure this out. I have seen users putting those grayish blocks in a comment.

I tried (<pre><code>) but that didn't work.


  • you mean like this?
    – tster
    Jul 2 '10 at 1:48
  • This belongs on meta
    – fmark
    Jul 2 '10 at 1:49

You can use backquotes to insert code in comments, just as you might insert inline code in a question or answer: printf("here is some code\n");

  • @Ether - I tried doing this. Text wrapped in backquotes displays a gray block in question or answer, but in comments it displays a highlighted box. How do I get the grey box in a comment? Jul 2 '10 at 2:23
  • @ShiVik: what dis the difference between a highlighted box and a grey box? Do they both use a monospaced font?
    – Ether
    Jul 2 '10 at 2:24
  • Yes. highlighted box is just white in background, it appears hightlighted when I hover the mouse over the comment which has it. Grey box is always highlighted grey whether I hover mouse over it or not. Jul 2 '10 at 2:31

use backticks "" <code here> "".

BTW, this belongs on meta.


Putting four spaces before the code will automatically generate the code block. Inside of a comment, you can wrap it with ` and it will demarcate the code. Or simply mark up the code that you want to be laid out as code and press the button with the 101010 label.


You can't, because the comments only support limited markdown tags.

Stop with the down votes - this was migrated while i was in the middle of editing it!! What i was busy clarifying is that it isn't a full code block - you don't get syntax coloring etc, just the highlighted background.

For the FAQ on comments check here. For the details on allowed markdown, check here.

  • 1
    You were probably downvoted because the OP mentioned specifically what he was looking for: "I have seen users putting those grayish blocks in a comment." Jul 2 '10 at 1:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .