CSS Comments

CSS comments are not displayed on the screen. It helps the developers to understand the source code & it applies inside a CSS file or style element.

Important fact regarding CSS Comment :
  • CSS comment is not displayed on the screen. It helps to understand the source code by the developers.
  • It applies inside any CSS file or inside <style>element.
  • It starts with /* and ends with */.
  • Multi Line Comments-Write more than one comment inside /* and */.

Note:The CSS comment statement does not display on the screen & it is useful for a screen reader.

Single Line Comment

Write a single line inside /* and */ to make a single-line comment.

General Syntax

      /* Single line comment  */
    
Try it now

Source Code

          p{
color: red;  /* Providing text color to red */
}
        
Try it now

Code Explanation

Note:The CSS single line comment statement is written inside / * Your CSS Comment Statement */ statement.

Multi Line Comment

Write more than one line inside /* and */ to make multi-line comments.

General syntax for writing multi line comment:

General Syntax

      /*
This is
a multi-line
comment 
*/
    
Try it now

Source Code

          p{
color: red; 
font-size:16px;
font-weight:400;

/* Setting text color to red and background color to green and
font-weight to 400 
*/
}
        
Try it now

Code Explanation

Note:Follow the above mention steps to create single and multi-line comments.

Difference Between HTML & CSS Comment

  • HTML comment starts with <!-- and end with -->
  • CSS comment starts with /* and end with */

Source Code

          /* CSS Comment */
p{
color: red; /* Set text color to red */
}    
<!--HTML Comment -->
<p>Learn to understand HTML & CSS comment</p>
        
Try it now

Code Explanation

Note:Please keep in mind that HTML and CSS comments are useful for screen readers as well as other developers.

Online Test / Quiz

Web Tutorials

CSS comments
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4