How to write code in a question/answer on a Stack Exchange site?


5 Answers 5


Before and after your code block press the ` (backtick) key followed by a blank space.

(Note: Do not mistake Backtick character and key ` with apostrophe character and key ') Thanks to @middaparka for the advice

Backtick key is here on most english keyboards:
backtick key

code block

(see Markdown Editing Help page)

  • 1
    This is a comment to show you that backtick key to mark inline code spans work on comments too: println('It works on comments too!'); Apr 22, 2011 at 22:03
  • And all my life I've been prepending every single line with 4 spaces
    – floribon
    May 17, 2016 at 13:52

Above the text box there is a button with curly braces. Mark your code and push that button.


If you add four spaces before a line, it will become code. Otherwise you can copy and paste your code into the text box. Select it, then press the {} button at the top of the form to turn it into code.


It tells you on the right side when you are writing the question. I believe it is 4 spaces in front of each line of code.


Put it within backticks or indent the lines with four spaces. This information is clearly provided to you when you go to the post-a-question link.