1

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

10

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

markdown
(see Markdown Editing Help page)

| improve this answer | |
  • 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!'); – Francisco Alvarado Apr 22 '11 at 22:03
  • And all my life I've been prepending every single line with 4 spaces – floribon May 17 '16 at 13:52
1

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

| improve this answer | |
0

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.

| improve this answer | |
0

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.

| improve this answer | |
0

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.

| improve this answer | |