2c. Comments in CSS

CSS Comments

  • Comments help with documentation and are helpful for the future users who read that code, so that they can understand it easily.

  • Comments are ignored by the browser and Comments don't affect the styling or layout.

  • CSS Comments are enclosed between /* & */.

  • If you are using vs code, you can use cltr + / to comment the line.

  • There are two types of comments in CSS:

Single-line comment:

Single-line comments are contained within one line. They are useful for short annotations.

Syntax

selector{
    /* property: value */
}

for example:

/* This is a single line commnent */

p{
    /* color: red */
}

here, the comment is between /* and */


Multi-line comments

Multi-line comments span across multiple lines, making them ideal for detailed explanations or temporarily disabling blocks of code.

Syntax

selector{
    /* property1: value1
    property1: value1
    property1: value1 */
}

These are similar to single-line comments, but this helps to comment large descriptions, notes, etc.

for example:

/* This is a
multi line
commment */
p {
    /* color: red;
    background-color: purple; */
    color: purple;
    background-color: red;
}