CSS comments let you add notes to stylesheets that browsers ignore. Use them to document code, organize sections, and temporarily disable rules during debugging.
01
/* */
Syntax.
02
Hidden
Not rendered.
03
Document
Explain code.
04
Disable
Debug rules.
05
No //
CSS only.
06
@charset
Comes first.
Fundamentals
Introduction
CSS comments are notes written inside a stylesheet for developers. They help you and your team understand why styles exist, mark sections of a large file, and leave reminders for future edits.
Definition and Usage
A comment is any text wrapped in /* and */. The browser completely ignores comment content — it does not affect layout, colors, fonts, or any visual output.
Comments are also useful for temporarily disabling CSS rules. Instead of deleting a rule while debugging, wrap it in a comment and restore it later.
💡
Beginner Tip
CSS does not support // comments like JavaScript. Always use /* */. A “single-line” comment is just a comment that fits on one line — the syntax is the same.
Foundation
📝 Syntax
Wrap comment text between /* and */:
syntax.css
/* This is a single-line comment *//*
This is a multi-line comment
It can span several lines
*/
Place comments anywhere in a CSS file — between rules, inside rule blocks, or at the end of a line:
inline-comment.css
/* Header styles */header{background:#2563eb;/* brand blue */color:#fff;}
Comment Types
Type
Description
Single-line
One comment on one line: /* note */
Multi-line
Comment spanning multiple lines for longer documentation
Inline
Short note after a property on the same line
Block disable
Wrap rules in /* */ to turn them off temporarily
/* comment */No // in CSSNot shown on page
Important Rules
Comments cannot be nested — the first */ closes the comment.
Comments do not appear on the rendered page but are visible in source and DevTools.
In external CSS, @charset must be the first line — no comments before it.
Never store passwords, API keys, or private data in comments.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Syntax
/* your comment */
// comments?
Not supported in CSS
Visible on page?
No
Disable a rule
Wrap it in /* */
Before @charset
Not allowed in strict external CSS
Nested comments
Not supported
Browser support
Universal
Context
When to Use Comments
Reach for CSS comments in these situations:
Section headers — Label groups like Header, Navigation, Footer in large files.
Explaining why — Document non-obvious values, hacks, or browser fixes.
Debugging — Temporarily disable rules to isolate layout problems.
Team handoff — Leave notes for other developers maintaining the stylesheet.
TODO reminders — Mark styles that need cleanup or refactoring later.
Skip comments that merely repeat what the code already says, like /* sets color to red */ above color: red;.
Preview
👀 Live Preview
Comments exist in your source code but never appear on the page:
In your CSS file/* This note is for developers */ body { color: #1e293b; }
What visitors seeStyled text only — no comment visible.
RememberCSS uses /* */ only. // does not work in stylesheets.
Hands-On
Examples Gallery
Practice CSS comments with basic syntax, commenting out rules, multi-line documentation, and inline notes.
🔠 Core Patterns
Start with basic syntax, then learn to disable rules temporarily.
Example 1 — Basic Comment
Add a single-line comment above your styles. The browser ignores it completely.
comment-basic.css
/* This comment is for developers only */body{font-family:system-ui, sans-serif;padding:1.5rem;color:#1e293b;}
Inline comments sit on the same line as a declaration. Use them sparingly for values that need context.
Tips
💬 Usage Tips
Explain why, not what — Good: /* fix Safari flex gap */. Bad: /* set display to flex */.
Section headers — Use banner comments to divide large stylesheets into clear regions.
Keep comments current — Update or remove notes when the code changes.
Short inline notes — One line after a tricky property is enough.
Use version control — Git tracks history; you do not need to keep old code in comments.
Watch Out
⚠️ Common Pitfalls
Using // syntax — // is not valid CSS and can break your stylesheet.
Nested comments — /* outer /* inner */ */ does not work; the first */ closes the comment.
Comments before @charset — Can invalidate @charset in external CSS files.
Outdated comments — Misleading notes are worse than no comments at all.
Secrets in comments — Comments are visible in source code and DevTools.
A11y
♿ Accessibility
Comments are invisible — Never put essential information only in comments; users cannot read them.
Screen readers ignore comments — Accessibility text must be in HTML content, not CSS notes.
Do not hide content via comments — Use proper CSS or HTML patterns instead of commenting out accessible markup.
Document a11y fixes — Comments can explain focus styles or contrast overrides for maintainers.
Keep file size reasonable — Very large comment blocks slightly increase CSS file size.
🧠 How CSS Comments Work
1
Parser reads CSS
The browser loads your stylesheet and scans for rules and declarations.
Parse
2
/* */ blocks are skipped
Everything between /* and */ is treated as a comment and ignored.
Skip
3
Valid rules are applied
Only non-commented selectors and properties affect the page appearance.
Apply
=
📝
Documented, styled page
Developers see notes in source; visitors see only the applied styles.
Compatibility
🖥 Browser Compatibility
CSS comments using /* */ have universal support in every browser, including Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Universal support
CSS /* */ comments
Comments work identically in all browsers and have been part of CSS since the beginning.
100%All browsers
Google ChromeAll versions
Full support
Mozilla FirefoxAll versions
Full support
Apple SafariAll versions
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
CSS comments100% supported
Bottom line:/* */ comments work everywhere. The only syntax to remember is that CSS does not support //.
Wrap Up
🎉 Conclusion
CSS comments are a simple but essential tool for writing maintainable stylesheets. Use /* */ to document your code, organize sections, and temporarily disable rules during development.
Write comments that explain why, keep them up to date, and never put sensitive data inside them. With good commenting habits, your CSS becomes easier for everyone on your team to understand.
Explain non-obvious styles and browser workarounds
Add section headers in large stylesheets
Update comments when code changes
Use comments to disable rules during debugging
❌ Don’t
Use // — it is not valid CSS
Comment on every obvious line of code
Store passwords or API keys in comments
Place comments before @charset in external CSS
Leave large blocks of dead code commented out permanently
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about CSS comments
Use these points when writing and maintaining stylesheets.
5
Core concepts
/*01
Syntax
/* */ only.
Core
hide02
Invisible
Not on page.
Render
doc03
Document
Explain why.
Purpose
off04
Disable
Debug rules.
Debug
no//05
No //
CSS differs.
Rule
❓ Frequently Asked Questions
Wrap your note in /* and */. Everything between those markers is ignored by the browser. A comment can sit on one line or span multiple lines.
No. Comments are hidden from visitors. However, they are still visible in View Source, browser DevTools, and downloaded CSS files — never put secrets in comments.
No. Unlike JavaScript, CSS only supports /* */ comments. Using // will not work and may cause parsing errors depending on context.
Yes. Wrap a rule or block in /* */ to temporarily turn it off during debugging. Remove the comment markers when you want the styles back.
In strict interpretation, nothing — not even comments — should appear before @charset in an external CSS file. Place @charset as the very first line when you use it.