Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

CSS Comments

CSS Comments

Comments are employed to elucidate the code, aiding in future edits to the source code.

Browsers disregard comments.

A CSS comment is enclosed within the <style> element, commencing with /* and concluding with */.

Example

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

You have the flexibility to insert comments at any location within the code.

Example

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

 

Even within a single line of code, comments can be included.

Example

{
  color: /*red*/blue; 
}

Comments are also capable of extending across multiple lines.

Example

/* This is
a multi-line
comment */


{
  color: red;
}

HTML and CSS Comments

From the HTML tutorial, you discovered the ability to incorporate comments into your HTML source code using the <!–…–> syntax.

In the subsequent example, we employ a blend of HTML and CSS comments.

Example

<!DOCTYPE html>
<html>
<head>
<style>
{
  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>