CSS Comments
Comments in CSS are notes you write for yourself or other developers. They don’t affect how the browser renders the page, but they help explain your code, disable rules temporarily, or organize stylesheets.
Block Comments (Standard in CSS)
CSS supports C‑style block comments:
Code Block Loading...
You can also write multi-line comments:
Code Block Loading...
Example
Code Block Loading...
Inline Comments (Not Supported)
Unlike JavaScript or C, CSS does not support // inline comments. If you write:
Code Block Loading...
The browser treats // as a syntax error. It ignores that line and continues with the next one. This can make it look like the rule is commented out, but it’s actually broken CSS.
Best practice: Always use /* ... */ block comments in CSS. Avoid // to prevent confusion.
Why Comments Matter
- Documentation: Explain why a rule exists.
- Debugging: Temporarily disable rules without deleting them.
- Collaboration: Help teammates understand your intent.
- Organization: Divide large stylesheets into sections.