Geek Slack

Introduction to CSS
About Lesson



CSS Comments


CSS Comments

CSS comments are used to add notes or reminders within your CSS code. They are not displayed in the browser and can be helpful for documenting your styles.

Basic Syntax

CSS comments are written between /* and */ characters:

/* This is a CSS comment */

Example Usage

Comments can be used to describe sections of your CSS or to temporarily disable styles for testing purposes:

/* Main styles for the header */
header {
    background-color: #333;
    color: #fff;
}

/* Temporarily hide the sidebar */
/* .sidebar {
    display: none;
} */

Best Practices

  • Use comments to explain complex sections of your CSS code.
  • Keep comments concise and relevant.
  • Remove or update comments as you modify your styles.

Example of Well-Commented CSS

/* Base styles */
body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    background-color: #f9f9f9;
    color: #333;
}

/* Header styles */
header {
    background-color: #333;
    color: #fff;
    padding: 10px;
}

/* Main content styles */
main {
    padding: 20px;
}

/* Footer styles */
footer {
    background-color: #333;
    color: #fff;
    padding: 10px;
}

Conclusion

CSS comments are essential for maintaining well-documented and organized stylesheets. By using comments effectively, you can improve collaboration and easily manage your CSS code.

Join the conversation