Does CSS Support Single-line Comments?

Kenton de Jong
Geek Culture
Published in
3 min readJun 15, 2021

--

We’re talking about //baby

No, I’m not talking about /*these comments*/ , I’m talking about //these comments , the ones every other language supports.

(Except HTML.)

You’ve probably been told that no, CSS does not support single-line comments. The only way to leave a comment in CSS is with the slash-asterisk-asterisk-slash comments, like so:

div {
background-color: red; /*red makes people hungry*/
width: 200px;
}

You will find those claims on CSS Tricks, MDN and W3Schools (boo, I know). But what if I said those claims are false?

Please…

If you try something like this:

div {
background-color: red; //red makes people hungry
width: 200px;
}

It hides the subsequent style (aka the width). With this in mind, we could do something like this:

div {
//background-color: red; red makes people hungry
width: 200px;
}

Which would hide the background color... except it doesn’t. It hides the width, since that is the proceeding style. So you’d need to do this to comment out the background-color:

--

--

Kenton de Jong
Geek Culture

I am a web developer turned travel blogger that is forced to code to eat.