Menu
Fundamentals

CSS Comments

Understand how to add comments to your CSS code.

1Adding Comments

Comments are ignored by browsers and help explain your code.

Example Code
css
/* This is a single-line comment */
p {
  color: red; /* Inline comment */
}

/* Multi-line
   comment */

2Understand it in a real interface

Use comments to explain a decision that is not obvious from the declaration itself, such as a browser workaround or a deliberate spacing exception. Comments do not run as CSS. Removing them should leave the stylesheet with the same behavior, although they may be useful to future maintainers.

3Try it yourself

Write a small card rule and add a comment explaining why its width is constrained. Temporarily comment out one declaration and compare the result. Restore it, then check that the comment delimiters close correctly before the next rule.

Finished reading?

Mark this topic as complete to track progress.