By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

CSS Comments

How to efficiently use Comments in CSS

Edited: 2012-01-20 00:03

In CSS comments begin with "/*" and ends with "*/". This allows us to write multi-line comments, as well as single-line comments.

Note. Comments are ignored by browsers.

You can use comments whenever you want, they are especially useful when keeping track of what the many different portions of code dose, and/or when you are multiple people working on the code. Below are some valid ways of writing comments in css.

Single line CSS comment

The below is a common comment, often used to indicate sections in code.

body { /* This is a Comment */
}

Properties mixed with commenting

Though it looks like a complete mess, you can also write comments inside of CSS declarations.

     font-size: /* This is a Comment */ 2em;
}

Comments beside properties

You will often find small comments next to CSS declarations, used to describe what the declaration is used for.

    p {
      font-size: 1.5em; /* This is a Comment */
    }

Multi-line CSS comments

Finally we got the multi-line comment, which can be used to enter longer descriptions, copyright information, etc.

/* This is
 a multi-line 
 Comment */