Categories
CSS Tutorials

CSS comments

In CSS we will write hundreds of lines. If we want to change one style we need to search the entire page. So to make it easy, comment is the best option to find required code to change. For example if we are writing styles for header section, it is better to give comments as

/* header section styles */

So it is easy to change styles in the future. Comments can be spread over more than one line like this:

/* This is a CSS comment 
that is spread over 
multiple lines.The browser
ignores everything until 
the end of this line. */

Comment tags can also be used to disable part of your CSS temporarily. This is a useful technique when experimenting with new ideas or troubleshooting problems. Just put the opening /* and closing */ comment tags around the section that you want to disable. You can disable a single declaration or a whole section at a time. For example, this disables the color and background-color properties in the following rule:

body {
 font-family: Arial, Helvetica, sans-serif;
 /*color: #000;
 background-color: #FFF; */ 
}

Just remove the comment tags to restore the rules.

Example:

<html>
  <head>
      <style>
        h1 {
            color: green;
        }       
        /* Single line comment */
      </style>
  </head>   
  <body>
      <h1>Hello Everyone</h1>       
      <p> This is Edupoly training and development</p>
  </body>
</html>