CSS Comments
Learn how to write CSS comments — single-line and multi-line — and how to comment out CSS code for testing. Understand when and why developers use comments in their stylesheets.
- What are CSS Comments?
- Comment Syntax
- Single-Line Comments
- Multi-Line Comments
- Commenting Out Code
- Organising with Comments
- Rules & Mistakes
- Related Lessons
- Try It
- FAQ
What are CSS Comments?
A CSS comment is text you write inside your CSS code that the browser completely ignores. Comments are only visible to developers reading the source code — they never appear on the webpage and never affect any styling.
If you've already been through the CSS Introduction lesson, you already know that CSS rules have a selector, property, and value. Comments live outside that structure — they're notes you leave in the file. CSS comments serve two main purposes: explaining code and temporarily disabling CSS rules.
CSS Comment Syntax
CSS uses only one type of comment syntax. A comment starts with /* and ends with */. Everything between these two symbols is ignored by the browser — no matter how long or how many lines it spans.
/* This is a CSS comment — the browser ignores this */ p { color: blue; /* This comment explains the rule */ }
Single-Line Comments
Single-Line CSS Comments
CSS has no dedicated single-line comment syntax (unlike JavaScript which uses //). But you can write a short comment on one line using the same /* */ syntax — just keep it on one line. Place it before a rule or at the end of a declaration line.
/* Change the background color of the page */ body { background-color: lightblue; } /* Style for main heading */ h1 { color: darkblue; text-align: center; /* centers the heading */ } /* Single line comment */ p { color: red; }
Multi-Line Comments
Multi-Line CSS Comments
You can write a comment that spans multiple lines — just open with /* and close with */ anywhere. Everything in between, even across many lines, is completely ignored. Multi-line comments are great for longer explanations or file header blocks.
/* This is a multi-line comment. It can span as many lines as needed. Great for explaining complex CSS blocks. Author: TipsInLearning Date: 2026 */ h1 { font-size: 40px; color: #7c3aed; }
Commenting Out CSS Code
One of the most useful things about comments is that you can wrap CSS rules inside a comment to disable them temporarily — without deleting the code. This is very common during development and debugging.
p { color: blue; font-size: 20px; }
p { color: blue; /* font-size: 20px; */ }
/* Disable a single property for testing */ p { color: blue; /* font-size: 20px; */ } /* Disable an entire CSS rule block */ /* h1 { color: red; font-size: 40px; } p { color: green; } */ /* This rule is still active */ body { background: #f8fafc; }
Developer tip: Instead of deleting CSS when testing, comment it out first. If removing it breaks something, you can quickly uncomment it to restore it. This saves time during debugging and is a habit all professional developers use.
Organising CSS with Section Comments
In professional CSS files, developers use section header comments to divide the stylesheet into clearly labelled areas. This makes large CSS files much easier to navigate and maintain — especially when working with a team.
/* ================================================ TipsInLearning — Main Stylesheet Author: TipsInLearning Last Updated: 2026 ================================================ */ /* ===== RESET & BASE STYLES ===== */ * { margin: 0; padding: 0; box-sizing: border-box; } /* ===== HEADER STYLES ===== */ header { background-color: #7c3aed; color: white; padding: 1rem 2rem; } /* ===== NAVIGATION MENU ===== */ nav { display: flex; gap: 20px; } /* ===== MAIN CONTENT ===== */ main { padding: 2rem; max-width: 1200px; } /* ===== FOOTER ===== */ footer { background: #0f172a; color: white; text-align: center; }
Rules & Common Mistakes
These rules about CSS comments are essential — getting them wrong will silently break your stylesheet:
Always Use /* */ in CSS
CSS has only one comment syntax. A comment opens with /* and must close with */. You can place comments anywhere in your stylesheet — before rules, inside rule blocks, or at the end of lines.
// This is wrong in CSS — this syntax does NOT work in CSS. It only works in JavaScript. If you use // in a CSS file, the browser won't treat it as a comment and it will break your CSS rule.
/* ✅ CORRECT — always use this in CSS */ p { color: blue; /* this works perfectly */ } /* ❌ WRONG — double slash does NOT work in CSS */ p { color: blue; // this BREAKS your CSS — use /* */ instead }
Related CSS Lessons
Comments work alongside the rest of your CSS knowledge. These lessons from the course connect directly with what you've just learned:
Try It Yourself
Questions About CSS Comments
The questions beginners most often ask when learning CSS comments: