How to enter code snippets in posts on Stack Overflow? I am getting frequent error messages while submitting posts with code. I am getting the following message:

Your Post appears to contain code that is not properly formatted as code.Please indent all code by 4 spaces using the code toolbar button or the ctrl+k keyboard shortcut.for more editing help , click the ? tool bar icon.

I have tried this by using ctrl+k -->enter code here and entered the code but I am getting the same error message. Also, I have tried using ">" before every line, even then the same message appears.

| improve this question | | | | |
  • A simple way: type the code, select the code, press Ctrl + K. And you should ask this question on Meta. – Yu Hao Aug 15 '13 at 5:34
  • Even here, this information is very searchable. For example, there are guidelines when writing your post with a link to more information. – chris Aug 15 '13 at 5:35
  • There's a ? icon at the top right of the box where you entered your question. Click it, then click "advanced help". – Keith Thompson Aug 15 '13 at 6:12

To create code blocks or other preformatted text, indent by four spaces:

This will be displayed in a monospaced font. The first four spaces
will be stripped off, but all other whitespace will be preserved.

Markdown and HTML are turned off in code blocks:
<i>This is not italic</i>, and [this is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

The $ character is just a shortcut for window.jQuery. If you want to have a preformatted block within a list, indent by eight spaces:

  1. This is normal text.
  2. So is this, but now follows a code block:

    Skip a line and indent eight spaces.
    That's four spaces for the list
    and four to trigger the code block.

StackOverflow guide.

| improve this answer | | | | |
  • 7
    Where did jQuery come from? – Paul Aug 15 '13 at 5:36
  • This is the most frustrating part of using StackOverflow for me. For YEARS, I still cannot get this to work. GitHub is so easy. Why not use support GitHub markup. – user24601 Aug 11 '18 at 17:02

Highlight/Select the code and press Ctrl+k.

| improve this answer | | | | |
  • Unfortunately, this does not work for me. – user24601 Aug 11 '18 at 17:02