12

Everytime I post CSS code on SO, I am slightly more annoyed by the incredibly incorrect syntax highlighting. So, I decided to make a post about it here. Every single other language has correct syntax highlighting, but CSS keeps getting problems.

According to this thread, (if I am understanding this correctly), code is automatically highlighted based on its tags, with that whole list being the specific tags. Now, there's also a second list there with extensions to the specific tags, in which CSS is also listed. So, based on that, I'd assume CSS should work, as long as the CSS extension is indeed added.

Based on that, I assume questions that have only the CSS tag should therefore also automatically get CSS highlighting for each of its answers. That is not the case, obviously (it's treating # as a comment, not an ID selector), so I'm wondering why. The pastebin linked in the meta.SE post also defines the CSS tag to lang-css.

So my question is, why do questions tagged with the tag, even when that's the only tag on the question, not show CSS higlighting?

PS: I am tagging this as a bug, because based on what I know (and listed above), this should not be happening.

3
  • That looks like it answers my question. Should I remove the [bug] tag now? Or should I just leave it as it is?
    – Joeytje50
    May 25, 2014 at 23:01
  • @psubsee2003 well, those 2 links do explain pretty well why it was removed, so I think I have my explanation why it's not highlighting the text. Also, going by those links, I don't think it'll be reimplemented until the code higlighting is able to automatically detect CSS code, so I won't go for the feature-request.
    – Joeytje50
    May 25, 2014 at 23:05
  • @balpha I noticed syntax highlighting has been re-enabled on Stackoverflow, but it seems kinda random when the highlighting is applied. For example this Q has the [html] and [css] tags and does have highlighted CSS, but this Q has only the [css] tag and doesn't have highlighting. Do you have anything to do with this change in highlighting, and if so, could you please leave an answer to this post explaining?
    – Joeytje50
    May 29, 2014 at 22:50

1 Answer 1

10

This actually isn't a bug. Originally, did get CSS Syntax highlighting, but it was removed due to issues related to CSS questions commonly also having the and tags, and because of issues with Prettify not detecting CSS code blocks correctly.

For some background on the issue, you can review these questions from Meta.StackExchange

However, you can still manually apply CSS highlighting to code. You can get the details in How do I format my code blocks?, but in short, the syntax is <!-- language: lang-css -->

3
  • 1
    <!-- language: lang-css --> doesn't seem to make it any different anymore. At least in the all-in-one CSS/JS/HTML widget output.
    – user241244
    May 26, 2019 at 15:14
  • @D_N if it isn't working, I suggest posting a new question to ask if the functionality was changed. i don't see a recent meta post asking about css syntax highlighting, so either it was recent or no one noticed it, or maybe there was another issue that caused it to not work May 27, 2019 at 11:22
  • @ user241244 it seems to be css now, instead of lang-css
    – Bogdan D
    Apr 29, 2022 at 9:51

You must log in to answer this question.

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