CHAPTER 5

CSS Comments

CSS comments are notes written inside CSS code. Browsers ignore comments when applying styles.

01. What is CSS Comments?

CSS comments begin with /* and end with */.
Comments can explain what a section of CSS does.
Comments are useful for organizing large stylesheets.
Comments do not change the visual output of the webpage.

02. Syntax

/* This is a CSS comment */ p { color: blue; } /* This is a multi-line comment */

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>

<head>

    <style>

        /* Main heading */

        h1 {
            color: #2563eb;
        }


        /* Paragraph styling */

        p {
            color: #555;
            font-size: 18px;
        }

    </style>

</head>

<body>

    <h1>AIFA CSS Lab</h1>

    <p>
        Comments help developers understand code.
    </p>

</body>

</html>

04. Important Points

✓ Comments are not displayed on the webpage.
✓ Comments can document difficult CSS sections.
✓ Use comments to divide large stylesheets into logical sections.

05. Common Mistakes

⚠ Using HTML comment syntax inside a CSS stylesheet.
⚠ Forgetting to close a multi-line comment.

06. Real World Use

Developers use comments to document navigation styles, responsive sections, components and complex CSS logic.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Add CSS Comments

Create a webpage and organize its CSS using comments for headings, paragraphs and buttons.