Unlike some languages, CSS has only one comment syntax, /* ... */, which can span multiple lines but cannot be nested — a second /* inside an already-open comment has no special effect, and the comment simply ends at the very next */ encountered, whichever one comes first. There's no single-line // comment syntax in standard CSS, unlike JavaScript, so even a short, single-line comment still needs the full /* ... */ wrapping.
1Understanding CSS Comments
Unlike some languages, CSS has only one comment syntax, /* ... */, which can span multiple lines but cannot be nested — a second /* inside an already-open comment has no special effect, and the comment simply ends at the very next */ encountered, whichever one comes first. There's no single-line // comment syntax in standard CSS, unlike JavaScript, so even a short, single-line comment still needs the full /* ... */ wrapping.
CSS comments cannot be nested — commenting out a block of CSS that already contains its own comment inside it will end prematurely at that inner comment's closing */, leaving the rest of the intended comment as active, unintended CSS.
/* Header styles */
.header {
background: black; /* matches the logo's background */
color: white;
}2Practical Example
Here is a real-world application of CSS Comments showing how it is used in production CSS code.
/* Temporarily disabling this rule while debugging
.sidebar {
display: none;
}
*/3Best Practices
Follow these guidelines when working with CSS Comments:
1. Use /* ... */ to document non-obvious CSS decisions, like why a specific magic number or an unusual override is needed
2. Comment out a block of CSS temporarily during debugging to test how the page behaves without it, rather than deleting and later having to rewrite it
3. Watch out for nested comments when commenting out a larger block that already contains its own comments, since the outer comment ends at the first inner */ it finds, not the last one
Tip: CSS comments cannot be nested — commenting out a block of CSS that already contains its own comment inside it will end prematurely at that inner comment's closing */, leaving the rest of the intended comment as active, unintended CSS.
/* Header styles */
.header {
background: black; /* matches the logo's background */
color: white;
}