A CSS comment is a note in a stylesheet. You write it between /* and */. The browser skips that text, so a comment does not change the layout.
The same markers cover one line and many lines. Use a comment to explain a rule, or wrap a rule in /* */ so the browser stops applying it while you edit. A stylesheet has no // comment. The first */ ends the note, so comments do not nest.
The first */ closes the comment.
/* outer /* inner */ ends at the first */. The second /* is just more comment text.
Syntax
CSS Syntax
One form, used for a short note or a longer one:
CSS
/* A one-line comment */
/*
A comment
which stretches
over several
lines
*/
p {
color: teal; /* brand color */
}
Reference
Where a Comment Can Sit
A comment is allowed wherever the stylesheet allows whitespace.
Place
Example
Remember
Before a rule
/* nav */ nav { }
The rule still applies
Between declarations
color: teal; /* note */
The declaration still applies
Around a whole rule
/* span { color: blue; } */
That rule is turned off
Across lines
/* line one line two */
Newlines stay inside the note
Nested note
/* a /* b */ c */
The first */ ends it
Two slashes
// note
Not a comment in a .css file
Code
CSS Examples
Three stylesheets. View Output shows what the page paints. The comment text itself stays off the page.
Example 1 — A note beside the color
The comment names the color. The paragraph is still teal.
CSS
/* Brand color for body text */
p {
color: teal; /* #008080 */
}
Output
Saved
How It Works
/* Brand color… */ sits where whitespace is allowed, before the rule.
/* #008080 */ sits after the declaration. The declaration is still color: teal.
The page shows Saved in teal. It does not show the words in the comments.
Example 2 — Turn a rule off
Wrap the blue rule in a comment. The span keeps the color it inherited.
The span rule is between /* and */, so the browser does not apply blue or 1.5em.
The p rule is outside the comment, so the text is #334155.
Delete the markers when you want the blue rule back.
Example 3 — The first */ ends the comment
A second /* does not open a nested comment. The teal rule sits after the first close, so it applies.
CSS
/* start
p { color: crimson; }
/* does not nest */
p { color: teal; }
Output
Teal, not crimson
How It Works
The comment opens at the first /* and includes the crimson rule.
/* does not nest */ ends at that */. The second /* was only text inside the note.
p { color: teal; } is real CSS after the comment, so the paragraph is teal.
Frequently Asked Questions
Open it with /* and close it with */. The same pair is used for one line and for many lines. The browser skips everything between those markers, so the comment does not change the layout.
No. A stylesheet has one comment form: /* */. Two slashes are not a comment. The tokens after // are still read as CSS.
No. The first */ closes the comment that the previous /* opened. A second /* inside the note does not start a new comment.
Wherever whitespace is allowed: before a rule, between rules, between declarations, and after a declaration on the same line. A comment is not a way to split a property name into two pieces.
The visitor does not see the note in the layout. The words stay in the CSS file, so they are visible in the stylesheet source. Use a comment for a note to the next reader, or to turn a rule off while you edit.