html
/

CSS Comments

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

html

CSS Comments

What are CSS Comments?

CSS comments are used to add notes or explanations inside your stylesheet. They are ignored by the browser.

Syntax

CSSRead-only
1
/* This is a comment */

Single Line Comment

CSSRead-only
1
/* Button styles */
button {
  background: blue;
}

Multi-line Comment

CSSRead-only
1
/*
  This is a multi-line comment
  Used for detailed explanation
*/
p {
  color: black;
}

Commenting Out Code

CSSRead-only
1
/* p {
  color: red;
} */

Use Cases

  • Explain complex styles
  • Temporarily disable code
  • Organize sections in CSS files
  • Add notes for team members

Best Practices

  • Write meaningful and clear comments
  • Avoid over-commenting simple code
  • Use comments to group related styles
  • Remove unnecessary comments in production

Common Mistakes

  • *Forgetting to close comment /
  • Using comments inside property values incorrectly
  • Leaving large blocks of unused code
  • Adding sensitive information in comments

Important Note

Comments are visible in the browser's source code. Avoid including sensitive or confidential information.

Conclusion

CSS comments improve readability and maintainability when used correctly. They are essential for clean and organized stylesheets.

Try it yourself

/* This is a comment */
p {
  color: blue;
}

Test Your Knowledge

Q1
of 3

What is correct CSS comment syntax?

A
// comment
B
<!-- comment -->
C
/* comment */
D
# comment
Q2
of 3

Are comments executed by browser?

A
Yes
B
No
C
Sometimes
D
Only JS
Q3
of 3

Where are comments visible?

A
UI
B
Console
C
Source code
D
CSS file only

Frequently Asked Questions

Are CSS comments visible on UI?

No, they are only visible in source code.

Can comments span multiple lines?

Yes, using /* and */.

Should comments be used in production?

Yes, but avoid unnecessary or sensitive content.

Previous

css selectors

Next

css colors

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.