Home CSS CSS Comments

CSS Comments

Beginner ⏱ 5 min read Updated: Jul 2026
  • CSS comments are used to add notes and explanations inside CSS code.
  • Comments are ignored by web browsers and do not affect webpage design.
  • CSS comments are written between /* and */ symbols.
  • Comments make CSS code easier to understand and maintain.
  • CSS comments are useful for developers when working on large projects.

What are CSS Comments?

CSS comments are lines of text written inside a CSS stylesheet to explain the purpose of code. They help developers understand the styling rules and make the code easier to manage.

Comments are not displayed on the webpage because browsers ignore them while reading CSS files. They are only visible inside the source code and are used as documentation for developers.

CSS comments are especially helpful when working on large websites where multiple developers work together. They allow developers to describe sections of code, explain complex styles, and organize CSS files properly.

Syntax of CSS Comments

In CSS, comments start with /* and end with */. Anything written between these symbols will be treated as a comment.

Example

/* This is a CSS comment */
h1 {
    color: blue;
}
p {
    font-size: 18px;
}
Result

CSS Comments Example

Comments are ignored by the browser.

Single Line CSS Comments

CSS does not have a separate single-line comment syntax. Instead, developers use the same /* */ symbols for both single-line and multi-line comments.

Example

/* Change heading color */
h1 {
    color: red;
}

Multi-Line CSS Comments

Multi-line comments are used when developers need to write longer explanations. They can contain multiple lines of text inside the comment block.

Example

/*
This section styles
the website header
and navigation menu
*/
header {
    background-color: black;
    color: white;
}

Example Explained

/* */

These symbols define the beginning and end of a CSS comment.

Comment Text

The text written inside comment symbols is ignored by the browser.

CSS Code

CSS rules outside comments are normally applied to HTML elements.

Why Use CSS Comments?

  • Comments improve code readability and understanding.
  • They help developers remember the purpose of specific styles.
  • Comments make teamwork easier in large projects.
  • They help organize different sections of CSS files.
  • They make future updates and maintenance easier.

CSS Comments for Temporarily Disabling Code

Developers can use comments to temporarily disable CSS code without deleting it. This is useful when testing different designs or debugging webpage styles.

Example

/*
p {
    color: green;
}
*/

💡 Note: The browser completely ignores CSS comments, so commented code will not appear on the webpage.

Best Practices for CSS Comments

  • Write clear and meaningful comments.
  • Avoid adding unnecessary comments for simple CSS properties.
  • Use comments to explain complex code sections.
  • Keep comments updated when changing CSS code.
  • Use comments to separate different sections of large stylesheets.

Conclusion

CSS comments are an important part of writing clean and maintainable CSS code. Although comments do not affect the appearance of a webpage, they help developers understand, organize, and manage styles more effectively.

By using CSS comments properly, developers can create better structured projects and make future changes easier. They are especially valuable when working on large websites and team-based projects.