CSS Comments

Beginner
6 min read
Updated: Nov 2026
3 examples
Stylesheet syntax

Definition and Usage

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.

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 */
}

Where a Comment Can Sit

A comment is allowed wherever the stylesheet allows whitespace.

PlaceExampleRemember
Before a rule/* nav */ nav { }The rule still applies
Between declarationscolor: 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// noteNot a comment in a .css file

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 */
}

How It Works

  1. /* Brand color… */ sits where whitespace is allowed, before the rule.
  2. /* #008080 */ sits after the declaration. The declaration is still color: teal.
  3. 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.

CSS
/*
span {
  color: blue;
  font-size: 1.5em;
}
*/

p {
  color: #334155;
}

How It Works

  1. The span rule is between /* and */, so the browser does not apply blue or 1.5em.
  2. The p rule is outside the comment, so the text is #334155.
  3. 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; }

How It Works

  1. The comment opens at the first /* and includes the crimson rule.
  2. /* does not nest */ ends at that */. The second /* was only text inside the note.
  3. 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.

Next: image sprites

Combine several pictures into one file and show a piece with CSS.

Image sprites tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful