I suppose this question has been asked here at least ten times, but it seems my searches have not been successfull so far.

But anyways, how to you put that fancy code coloring inside the <pre></pre> or <code></code> tags in a StackOverflow question? I tried the Ctrl+K but it just indents the statement.

  • Indented lines show up as Highlighted code, you should see that in the preview : )
    – Stephan B
    Mar 22 '11 at 11:45
  • The editing help should really be updated... see also this question.
    – fretje
    Mar 22 '11 at 12:28
  • 1
    possible duplicate of How do I format my code blocks?
    – Arjan
    Mar 22 '11 at 16:32
  • @Arjan, he's trying to get the Color in the codeblock, and not a code-block itself. Oct 6 '11 at 23:33
  • True, @fireDude67, but coloring is part of the formatting, and the answer is in that FAQ.
    – Arjan
    Oct 7 '11 at 10:46

You can choose the language per code block, and it will get proper colors.

For example, C# code block:

Example e = new Example();

Some HTML:


How to do this? Add such line above the code block, with one blank line between them:
<!-- language: lang-cs -->
This is for C#, it can be html, js and more.

For more details: Syntax highlighting: what about answering with a different language than the one used in the question?

Without specifying the language yourself, the language will be taken from the question tags.


The coloring is by-default for code indented with 4 or more spaces.

For more information refer Code and Preformatted Text

Here is an example

Example e = new Example();
  • 1
    Wow, the colors are stunning :-) (Ah, you posted this before the migration.) Mar 22 '11 at 12:15

I think this question is for meta.stackoverflow.com, but the code gets formatted automatically:

public class Test {
   public string MyString { get; set }

Just indent the code with 4 spaces and you're off into code mode.

You must log in to answer this question.

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