What are comments in a CSS file?
Need for comments
The most crucial yet ignored part of code (in any language across all development platforms) is the comments. Comments do not contribute to the actual compilation and execution of the code; instead, they serve as flags throughout the file that help you to navigate and understand the code.
Imagine your code as the street and the comments as street signs!
Ways to comment in CSS a file
There are essentially three ways you can comment in a CSS file:
- Single line comment
- Multiple line comment
- Style comment
Comments in the CSS file are encapsulated in-between /* and */.
Single- line comments
You can concatenate the start and end of your comment with /* and */ in the same line.
/*outside class single line comment*/
.my-class {
/*inside class single line comment*/
...;
...;
...;
}
/*
outside class
multiple line
comment
*/
.my-class {
/*
inside class
multiple line
comment
*/
...;
...;
...;
}
Multiple-line comments
Put /* a line above your multiple-line comment and */ below it.
Style comment
Encapsulate your styling class by putting /* above your class and */ below it.
.my-class {
...;
...;
...;
}
/*
.commented-class {
...;
...;
...;
}
*/
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved