It seems that language syntax highlighting is not working.

As I think we will have many answers involving small code fragments. Is it possible to enable this?

Few examples: 1, 2.

I used <!-- language: lang-... --> to specify the language in both cases.

  • $\begingroup$ Yes, and it should be auto-enabled for questions being tagged with a programming languages, like on Stack Overflow. $\endgroup$ May 30, 2017 at 13:57
  • $\begingroup$ I thought this kind of feature would be automatically enabled by the stackexchange engine. It would be a nice addition to have it. Readability counts. $\endgroup$
    – bli
    Jun 8, 2017 at 8:55
  • 2
    $\begingroup$ I've asked SE to activate this and they just told me they have. It should be live soon (there might be some caching issues involved). $\endgroup$
    – terdon Mod
    Jun 8, 2017 at 16:56
  • $\begingroup$ @KonradRudolph that can be set up by mods. The tag page a mod sees also has an option to associate a tag with a language. $\endgroup$
    – terdon Mod
    Jun 8, 2017 at 21:09

1 Answer 1


I mentioned this to an SE employee and they implemented it today! We now have working syntax highlighting!

Tags can have a specific language syntax associated with them. This is something that mods can set up. So, for example, if we were to ever have a or, more likely a tag, the mods could set it up so that it is associated with Perl syntax highlighting.

If a question isn't tagged with a tag that is associated with any specific syntax highlighting, we can still enable it using HTML comments. The syntax is as follows (using perl as an example):

<!-- language: lang-perl -->

Each code block you want to have highlighted must have a comment like the one above, an empty line, and then the code. For example, this:

<!-- language: lang-python -->


Will be rendered like this:

import foo
otherVar = None

Each code block in a question or answer needs its own HTML comment, and you need a blank line between the comment and the first line of code, as shown above. Here's the list of currently supported languages and their identifying string (the lang prefix is not needed if a tag has the language associated with it, but it won't harm it and we're unlikely to have many such tags anyway):

none:      none   ## Useful for disabling syntax highlighting
bash:      lang-bash OR lang-bsh
c:         lang-c
clj:       lang-clj
coffee:    lang-coffee
cpp:       lang-cpp
cs:        lang-cs
csh:       lang-csh
css:       lang-css
dart:      lang-dart
erlang:    lang-erlang
go:        lang-go
hs:        lang-hs
html:      lang-html
java:      lang-java
js:        lang-js
latex:     lang-latex
lisp:      lang-lisp
lua:       lang-lua
ml:        lang-ml
pascal:    lang-pascal
perl:      lang-perl
php:       lang-php
proto:     lang-proto
py:        lang-py
r:         lang-r
rb:        lang-rb
regex:     lang-regex
rust:      lang-rust
scala:     lang-scala
sh:        lang-sh
sql:       lang-sql
vb:        lang-vb
vhdl:      lang-vhdl
xml:       lang-xml
  • $\begingroup$ Did this stop working? I can’t seem to get anything highlighted, see e.g. here: bioinformatics.stackexchange.com/a/69/29 (both tagged, and the code is explicitly marked with a language). $\endgroup$ Jul 4, 2017 at 17:16
  • $\begingroup$ @KonradRudolph no, it works, it's just not very helpful for the code you posted. The snippet you had explicitly set a language for was colored but only in the words function and the 1E6 of log(1E6). The one you hadn't set explicitly wasn't colored because I hadn't associated the tag R with a language for syntax highlighting. I have now done so, so any future posts won't need the explicit <!-- language: lang-r --> anymore. $\endgroup$
    – terdon Mod
    Jul 4, 2017 at 22:38
  • $\begingroup$ Right, I forgot how … err … minimal Stack Overflow’s syntax highlighting is. Bit bizarre, given that programming languages is their core competence. $\endgroup$ Jul 5, 2017 at 10:40
  • $\begingroup$ @KonradRudolph AFAIK, they just use something developed by Google. And it does work OK for many cases. R doesn't seem to be one of them though, granted. $\endgroup$
    – terdon Mod
    Jul 5, 2017 at 10:47

You must log in to answer this question.

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