CSS comments are used to add notes or explanations to your CSS code. Comments are not displayed on the web page and are ignored by the browser.
There are two ways to add comments in CSS:
- Single-line comments: To add a single-line comment in CSS, you can use the
//
syntax. Anything after//
on a line will be treated as a comment. For example:
/* This is a CSS comment */
p {
color: red; /* This is another CSS comment */
}
/* This line is not a comment
But it can be a multi-line comment */
In the above example, the first and second lines are single-line comments, while the third line is an actual CSS rule.
- Multi-line comments: To add a multi-line comment in CSS, you can use the
/* ... */
syntax. Anything between/*
and*/
will be treated as a comment. This allows you to add comments that span multiple lines. For example:
/*
This is a multi-line CSS comment
that spans multiple lines.
*/
p {
color: red;
}
In the above example, the first three lines are multi-line comment, while the fourth line is an actual CSS rule.
Comments are useful for documenting your CSS code, explaining your thought process, or leaving notes for future updates. It’s good practice to use comments in your CSS code to make it more readable and easier to maintain.