More CSS Topics: CSS Comments

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


CSS gives you the ability to write comments in a CSS file, or in the style tag in the page header

The format is the /* this is a comment */ C-style (or JavaScript-style, if you prefer) comments.

This is a multiline comment. Until you add the closing */ token, all the lines found after the opening one are commented.

Example:

#name { display: block; } /* Nice rule! */

/* #name { display: block; } */

#name {
	display: block; /*
	color: red;
	*/
}

CSS does not have inline comments, like // in C or JavaScript.

Pay attention though - if you add // before a rule, the rule will not be applied, looking like the comment worked. In reality, CSS detected a syntax error and due to how it works it ignored the line with the error, and went straight to the next line.

Knowing this approach lets you purposefully write inline comments, although you have to be careful because you can’t add random text like you can in a block comment.

For example:

// Nice rule!
#name { display: block; }

In this case, due to how CSS works, the #name rule is actually commented out. You can find more details here if you find this interesting. To avoid shooting yourself in the foot, just avoid using inline comments and rely on block comments.

Lessons in this unit:

0: Introduction
1: CSS Variables (Custom Properties)
2: Importing a CSS file using @import
3: CSS Inheritance
4: ▶︎ CSS Comments
5: CSS Normalizing
6: The CSS z-index property
7: The CSS float property and clearing
8: CSS Feature Queries
9: How to print your HTML with style
10: CSS Vendor Prefixes
11: How to style lists using CSS
12: Styling HTML Tables with CSS
13: CSS Error Handling
14: Introduction to PostCSS