Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't we have a // comment in CSS? [duplicate]

Tags:

Possible Duplicate:
Why do /**/ comments work in stylesheets but // comments don't?

In CSS there is only one way to create comments: /* I'm a comment */

The problem is that it isn't nestable.

Does anyone know why we don't have an alternative comment syntax like //?

like image 833
Wabbitseason Avatar asked Jan 11 '11 10:01

Wabbitseason


People also ask

Can you comment in CSS?

To comment in CSS, simply place your plain text inside /* */ marks. This tells the browser that they are notes and should not be rendered on the front end.

How do I comment all in CSS?

The /* */ comment syntax is used for both single and multiline comments. There is no other way to specify comments in external style sheets. However, when using the <style> element, you may use <! -- --> to hide CSS from older browsers, although this is not recommended.


1 Answers

I think the real answer is that CSS treats newlines like any other whitespace, so it wouldn't make sense to have comments that are terminated by a newline. This is from the CSS1 spec: http://www.w3.org/TR/REC-CSS1

A CSS style sheet, for any version of CSS, consists of a list of statements. There are two kinds of statements: at-rules and rulesets. There may be whitespace (spaces, tabs, newlines) around the statements.

Of course, this also makes a lot of sense in the context of minification, as mentioned here: Why do /**/ comments work in stylesheets but // comments don't?.

like image 158
Spiny Norman Avatar answered Oct 23 '22 14:10

Spiny Norman