CSS ยท Chapter 5 of 44

CSS Comments

Comments in CSS start with /* and end with */. They are ignored by the browser and used to explain code or temporarily disable rules.

Comments can span multiple lines and are useful for organizing large stylesheets into sections.

Syntax
/* This is a comment */

Writing comments

Wrap any text with /* ... */ to create a comment. Unlike HTML comments, CSS uses this single style everywhere.

Uses for comments

Comments help document sections of a stylesheet, explain tricky rules, or comment out code while debugging.

Example 1 (css)
/* Header styles */
header {
  background: navy;
}

/* Footer styles */
footer {
  background: gray;
}
Output
Comments are ignored; only the styles apply

Comments label sections but produce no visual output.

Key points

  • CSS comments start with /* and end with */.
  • Comments are ignored by the browser.
  • Comments can span multiple lines.
  • Useful for documentation and debugging.
๐Ÿ’ก Note: Unlike some languages, CSS has no single-line // comment syntax.

๐Ÿ“ Quick Quiz

1. How do CSS comments start?

2. Are CSS comments rendered by the browser?

3. Can CSS comments span multiple lines?