CSS Comments

How to efficiently use Comments in CSS

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 */

Post comment

Links that you insert are not nofollowed, but will be removed by admins if they are considered spam.

[url=Absolute URL for page]TITLE[/url]

You should insert code boxes around code examples, which will be automatically syntax highlighted.

[code1 html|css|javascript|php|sql]Your Code Here[/code1]

You may want to read our Privacy Policy before submitting your comment.