CSS Comments

The browser does not display CSS comments, but comments of CSS can help in documenting your source code.

 

CSS Comments

CSS Comments explain the code and may help when you edit the source code later. Unfortunately, the browsers ignore the comments.

A CSS comment is placed inside the <style> element, and starts with /* and ends with */:

Example :

/* This is a single-line comment */
p {
  color: red;
}

Comments can be added anywhere in the code:

Example :

p {
  color: red;  /* Set text color to red */
}

Comments can also spread across multiple lines:

Example :

/* This is
a multi-line
comment */

p {
  color: red;
}

 

HTML and CSS Comments

You learned from the HTML tutorial that you can add comments to your HTML source by using the <!--...--> syntax.

In the example given below, a combination of HTML and CSS comments is used:

Example :

<!DOCTYPE html>
<html>
<head>
<style>
p {
  color: red; /* Set text color to red */
}
</style>
</head>
<body>

<h2>My Heading</h2>

<!-- These paragraphs will be red -->
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are not shown in the output.</p>

</body>
</html>

Try With Example