Unapologetic

By Alex Guyot ("Ghee(As in "geesegoose")-yo")

Double-click for controls.

Double-click to expand.

Double-tap for controls.

Double-tap to expand.

Fallback logo image for when CSS 3D transforms fail or are unavailable.

Single Line Comments in CSS

January 25, 2014

Tab Atkins Jr., a member of the CSS Working Group, reveals a nice tip about single line comments in CSS using //:

CSS uses the same “block comment” syntax as the C-like languages - you start a comment with /*, and end it with */.

However, CSS is missing the “line comment” syntax that those languages have, where everything from // to the end of the line is commented out.

People have asked for this syntax to be added repeatedly, but unfortunately our hands our mostly tied - CSS minifiers don't know about line comments, so if we added it and the minifier removed all the linebreaks (as they tend to do), the line comment would accidentally comment out the entire rest of your stylesheet!

That said, CSS does actually already allow you to use //, after a fashion. It's not quite a line comment, but a next construct comment.

That is, whenever you use //, the next CSS construct - either declaration or block - will be “commented out”.

I despise having to add the extra */ at the end of every CSS comment block, and having to remember to remove it every time I want to uncomment something annoys me even more. This is a tip I'll be using quite often.