Occasionally when I post a question on StackExchange and I copy and paste a code sample, when I publish the post, the code sample does not appear to color parts of the code like syntax highlighting. I have even had other members edit my post to add the coloring, but I don't know how to do this.

Is there a reason why pasted code would not be colored? I am using the 4 spaces preceding the code block and the code sample does appear with a grey background.


Syntax highlighting is automatically applied when certain tags appear under the question. For instance, a tag will apply Python-centric highlighting to all code blocks.

The highlighting can be modified or applied block by block by preceding it immediately with a comment (not indented) of the form

<!-- language: lang-blahblah -->

where "blahblah" is the name of the language. From what I can tell, it is case sensitive and should always be lower case. This comment will not be visible in the rendered post.

For details and a (somewhat incomplete) list of supported languages, please visit the Meta SO thread at Syntax highlighting language hints.


StackExchange sites use Google-Code-Prettify for syntax highlighting of code snippets in a web page. so you can check out readme(FAQ) page for lots of information.

  • For which languages does it work?
  • How do I specify the language of my code?
  • It doesn't work on ?
  • Which browsers does it work with?
  • How do I put line numbers in my code?
  • How do I prevent a portion of markup from being marked as code?

i hope it helps you...


This is a test of the language tag. (I can't get it to work)

public static IPolyline MakePolyline(IPoint p1, IPoint p2)
    var polyline = new PolylineClass() as IPolyline;
    ((IZAware)polyline).ZAware = true;
    ((IMAware)polyline).MAware = true;
    polyline.SpatialReference = p1.SpatialReference;
    return polyline;
  • (1) Please note my admonition "not indented." You also need to separate the comment from the following code by at least one blank line. (2) I don't believe the syntax highlighting works on meta sites. Try it on our main site.
    – whuber
    May 18 '13 at 17:23
  • I think option 2 is the reason. I tried editing this answer previously to include everything in option 1, but the edit did not work (so was never committed).
    – user3461
    May 19 '13 at 12:07
  • Kirk, I have edited the indentation in your test (none for the comment, four spaces for the code) to indicate how it's properly done on the main site. If you copy and paste it into a new question and then wait a couple seconds, you will see the syntax highlighting appear.
    – whuber
    May 19 '13 at 15:30

You must log in to answer this question.

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