How to Add Comments in CSS ?

In CSS, you can add comments to your code to provide explanations, notes, or reminders for yourself or other developers. CSS comments are not displayed on the web page and are meant for documentation and organization. There are two ways to add comments in CSS:

Single-line comments:

  • Use /* ... */ to enclose your comment. Everything between/* and */is treated as a comment.

/* This is a single-line comment */
body {
  background-color: #f0f0f0; /* Set the background color to light gray */
  color: #333; /* Set the text color to dark gray */
}

Multi-line comments:

  • You can also use /* to start a multi-line comment and */ to end it. This allows you to add comments that span multiple lines.

/*
  This is a multi-line comment.
  It can span multiple lines.
  You can use it to provide detailed explanations.
*/
body {
  font-family: Arial, sans-serif;
}

Here’s an example with both single-line and multi-line comments used in a CSS stylesheet:


/* This is a single-line comment at the beginning */

body {
  background-color: #f0f0f0; /* Set the background color to light gray */
  color: #333; /* Set the text color to dark gray */
  /*
    The following rules apply to the text inside a div element.
    This is a multi-line comment.
  */
}

/* This is another single-line comment at the end */
Previous
What is Class and ID for in CSS ? CSS - Basic Selectors - Tags, Class, ID, Important.
Next
The CSS Display Property – Display-Block, Inline-Block, None