How to Write Comments in CSS
A CSS comment starts with /* and ends with */. The browser skips everything between them, so a comment can hold a note for the next reader, or switch a rule off without deleting it.
Syntax
/* <comment> */
| Part | What it does |
|---|---|
/* | Starts the comment. |
<comment> | Anything: a note, or rules to switch off. It can run over several lines. |
*/ | Ends the comment, at the first */ after the start. |
MDN's Comments page says this is the only comment syntax in CSS, and that comments can be placed wherever white space is allowed.
The Example
The example is a page of opening hours. A comment names the heading's rule, and a second comment switches off a rule that would color the paragraph red.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Comments</title>
<style>
/* Main heading */
h1 {
color: #0f6cbd;
}
/* Switched off for now:
p {
color: #c50f1f;
}
*/
</style>
</head>
<body>
<h1>Opening hours</h1>
<p>Monday to Friday, 9:00 to 17:00.</p>
</body>
</html>
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- The heading is blue. The comment above its rule changed nothing.
- The paragraph is black, not red. Its rule is inside the second comment, so Chromium never read it: the page's style sheet held only the
h1rule. - Neither comment shows on the page.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Starting a comment with // | CSS has no // comment. The line became part of the next rule's selector and broke it: with // Main heading above the h1 rule, the heading stayed black | Use /* */ |
| Putting a comment inside a comment | Comments can't be nested: the first */ ends the comment, and the rest broke the rule after it, so the heading stayed black | Close each comment before starting another |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The rule right after a comment does nothing | The comment uses //, or it's nested | Rewrite it as one /* */ comment |
FAQ
Can a comment go inside a rule?
Yes. color: #0f6cbd; /* brand blue */ inside the h1 rule worked: the heading was blue, and the next declaration in the rule applied too.
How do I switch a rule off for a while?
Wrap the whole rule in one comment, as the example does with the p rule. Remove the /* and */ to switch it back on.
Conclusion
Write CSS comments between /* and */, for notes or to switch rules off. Never use //, and never put one comment inside another: both break the rule that follows.
Additional Resources
- Comments, on MDN.
