Search code examples
csscommentsmultiline

Is there a best practice for multi-line CSS comments?


Sometimes, when I find CSS comments that span multiple lines, I see them indented with spaces or a space and asterisk. I find these to be more readable, but there's no mention of them in the CSS specifications. Is it considered better to indent CSS comments, or to just add the /* and */ strings without otherwise changing the text of the comment?

Examples:

/*
  The quick
  brown fox
  jumps over
  the lazy dog.
*/

/*
 * The quick
 * brown fox
 * jumps over
 * the lazy dog.
 */

/*
The quick
brown fox
jumps over
the lazy dog.
*/

Solution

  • There isn't a single best practice that everyone does. But I think everyone will agree with these:

    1. Be clear. Find a layout that's easy to read, and don't let your comments obscure the code.
    2. Be consistent. Don't do it differently in different places. Although you might have one way to do comments about an entire declaration, and another for a single property (you could put the latter after the property on the same line, for example.)