CSS comments allow us to write notes and explanations in the code. These are ignored by the browser and are only intended for developers.
In CSS, comments are always placed between /* and */. They can be used on a separate line or at the end of a line of code.
In larger projects, comments help in structuring the code, for example marking separate sections or recording important information.
In larger projects, comments are often used to create section headers that help with quick orientation in the code.
When CSS is minified, comments usually disappear. If you want certain comments (such as license information) to remain, use the /*! ... */ syntax.
The most common mistake is when the comment is not closed. In that case, the entire file becomes invalid. Also note that // style comments are not valid in CSS.
Comments can effectively support the readability and maintainability of code. Here are some suggestions:
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.