CSS – Comments

The comments in CSS are used to describe the code and are ignored by the web browsers i.e. whatever you mention in the comments won’t be displayed.

To add comments, use:

/* This is a comment in CSS   */

The following are the type of comments in CSS:

  • Single-line comments
  • Multi-line comments

Single-line comments in CSS

Allows you to set single-line comments as in the below example:

<!DOCTYPE html>
<html>
<head>
<style>
p {
    border-style: solid; /*  Set the border style  */
    border-color: blue;  /*  Set the border color  */
    border-width: 3px;   /*  Set the border width  */
}
 
</style>
</head>
<body>
 
<h2>Studyopedia</h2>
<p>A website with courses on programming and web development.</p>
 
</body>
</html>

When we will run and get the output, the comments won’t be visible on the web page:

CSS Comments

Multi-line comments

To span comments on multiple lines at a time, use the multi-line comments in CSS. Let us see the above example and set multi-line comments which won’t be visible on the web browser:

<!DOCTYPE html>
<html>
<head>
<style>
/*
Set border style, color
and width
*/
p {
    border-style: dashed; 
    border-color: red;
    border-width: 2px;
}
 
</style>
</head>
<body>
 
<h2>Studyopedia</h2>
<p>A website with courses on programming and web development.</p>
 
</body>
</html>

When we will run and get the output, the multi-line comments won’t be visible on the web page:

CSS comments

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


Read More:

CSS Lists
CSS - Margins
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment