Edit Template
Edit Template

CSS Comments

What Are CSS Comments?

CSS comments are notes that developers include in the stylesheet to explain the code, add reminders, or temporarily disable certain styles.

They do not affect how the web page looks – the browser completely ignores them.

Why Use Comments?

  • To make code easier to understand – for yourself and others.
  • To document why a certain style was added.
  • To temporarily disable specific styles during development or testing.

Syntax

All CSS comments are wrapped between /* and */ .

				
					 /* This is a CSS comment */
				
			

There are two types of comments in CSS:

Single-Line Comments

Single-line comments are typically short notes written on a single line.

Syntax:

				
					/* This is a single-line comment */
				
			

Example:

				
					p {
    /* color: red */  /* This line is disabled */
    color: blue;
}

				
			

In this example, the color: red; rule is ignored by the browser because it’s inside a comment.

Multi-Line Comments

Multi-line comments are used for larger blocks of text or when disabling multiple styles at once.

Syntax

				
					/* 
    This is a multi-line comment.
    It can span multiple lines.
    Useful for larger explanations.
*/

				
			

Example:

				
					p {
    /* 
    color: red;
    background-color: purple;
    */
    
    color: purple;
    background-color: red;
}

				
			

Here, the first two properties are commented out, and the new ones take effect.

Tip: If you’re using VS Code or a similar editor, select the line or block of code and press Ctrl + /.
This shortcut automatically comments or uncomments the selected lines.

Scroll to Top