Single-line comments

I’m sure this has been discussed many times before, but is there any reason why this cannot be supported?

Of course its supported:

body {
  /*My Comment*/

That’s one line.

Now I’m sure what your talking about is double backslashes // My comment

Well each language has its own way, just like in HTML its <!-- -->

Yes, sorry, I meant with the double-slash syntax (as used in C++, C#, PHP, JavaScript, etc.)

For one thing, it would break stylesheet.replace(/\n/g,'').replace(/\s/g,' ') as a minification strategy. (In other words, it doesn’t play nice with inline styles.)

Minifiers can simply replace single-line comments with multi-line comments before removing line ending characters.

Main complaint about single-line comments in CSS is typically that double slash in nonquoted absolute URLs would be incorrectly treated as beginning of a comment.

This could probably be solved by allowing each single-line comment to be the only contents of its line (with guaranteedly nothing before the comment), but some CSSWG people who like the word “confusing” would probably call this confusing.

1 Like