1

In how many ways and places can we place comments in CSS?

Can the placement of comments create any problems in CSS rendering and validation?

3 Answers 3

8

The CSS specification spells this out definitively:

Comments begin with the characters /* and end with the characters */. They may occur anywhere between tokens, and their contents have no influence on the rendering. Comments may not be nested.

CSS also allows the SGML comment delimiters (<!-- and -->) in certain places defined by the grammar, but they do not delimit CSS comments. They are permitted so that style rules appearing in an HTML source document (in the STYLE element) may be hidden from pre-HTML 3.2 user agents. See the HTML 4 specification ([HTML4]) for more information.

For example:

.row {background-color:#FFF;}  /* normal */
.row:hover {background-color:#CCC; /* grayed background */}
 
/* the title class */
.title{
    /* make font bigger */
    font-size: 160%;
}
Sign up to request clarification or add additional context in comments.

Comments

0

The only kinds of comments allowed in CSS are the /* ... */ block delimiters. They can be placed almost anywhere, as if you were using them in any other language (that uses those kinds of comments, of course).

Comments

0

You can use the /* */ syntax for block comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.