Forum Moderators: not2easy

Message Too Old, No Replies

CSS Comments Syntax

CSS comments

         

korkus2000

3:49 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are all the ways to comment CSS? I know about /* */ but are there any others possible, even outside of spec?

DrDoc

3:52 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's just /* */

Some browsers randomly support other ways as well (such as HTML style comments <!-- --> if the page is XHTML)... But /* */ is your only safe bet, and the only type of comment that should be used.

DrDoc

3:53 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check this page out, from W3C:
[w3.org...]

korkus2000

3:58 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to parse css files and want to catch other possible comments allowed by browsers. Do you think <!-- --> comments are used? Does this cause errors on any browsers?

DrDoc

4:04 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!-- --> are probably the most widely used ones (unfortunately).

A ton of people still use:

<style type="text/css">
<!--
styles here
-->
</style>

...even though that was never part of the CSS recomendations to begin with. It just exploited ancient browsers inability to render styles altogether, in which case they would otherwise display the styles as plain text.

However, since those browsers are dead, there's no need for using HTML style comments.

And yes, they cause problems. Any XML based user agent is allowed to silently remove anything inside the comments. This means, for example, that Gecko (at least Netscape) will not render any styles on an XHTML page using <!-- -->.

korkus2000

4:06 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good point, I never thought of that. Thanks Doc!