Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Possible Duplicates:
How to post code in SO
How do I format my code blocks?

when i post code here is ends up all mangled, how do i make it look pretty?

for example posting //#include (minus the //) ends up looking like this:


what am i doing wrong?

share|improve this question

migrated from May 25 '10 at 17:23

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Andrew Grimm, Pops, Jon Seigel, waiwai933, ChrisF Mar 30 '11 at 8:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Isn't there an explanation to the right of where you type the question? – Earlz May 25 '10 at 18:46
Actually there doesn't seem to be a duplicate for this question, though an old one of mine is related… Maybe this should be a FAQ? – Earlz May 25 '10 at 18:47

If you post code or XML, highlight those lines in the text editor and click on the "code" button (101 010) on the editor toolbar to nicely format and syntax highlight it.

alt text

share|improve this answer
@marc_s -- not a circle, not freehand, it is red and points in roughly the correct area; I give it a 5.5. – tvanfosson May 25 '10 at 20:26
@tvanfosson: out of 6? Not bad..... heck - I'm a dev, not a graphics artist! ;-) You don't want to see my complete UI's...... – marc_s May 25 '10 at 20:29
This method worked for me, It will automatically detect the language. Example : Java for me. – vanduc1102 May 3 '15 at 11:21
Only works in answers, not in comments on answers. However, backticks work in both. – Dave Burton Feb 26 at 12:17
I don't see the 101010 button when writing a question. – quant_dev Mar 20 at 9:21

You surround your code in backticks `` (like this)

Or for block code, you indent your code by four spaces:

function test()
    alert("it works!")

You can view the source for this post here.

share|improve this answer

If you want to do this manually, you add 4 spaces in front of every line of code.

With the editor, there is a code button (101010) you can press after highlighting the code.

share|improve this answer

You can also use keyboard shortcut: just highlight and hit ctrl-k

share|improve this answer

like this, highligh what you want then click the code button

share|improve this answer
you can use this shortcut ctrl+k – Abdul K Shaikh Jan 30 '15 at 20:43

I think this is one of those things that should belong on or some such, but... in the post box, if you click the orange question mark in the top-left of the box, it will take you to a page with Markdown help. Basically, you prefix each line with four spaces:

like this 

and you should see the text show up as 'code' in the preview area below the edit box.

share|improve this answer