Lecture

Comment

How can you document certain code or temporarily disable parts of it while writing CSS?

In such cases, you use CSS comments.


How to Use CSS Comments

CSS comments start with /* and end with */.

CSS
/* This is a CSS comment. */ body { background-color: lightblue; }

Uses of CSS Comments

  1. Code Explanation: Add comments to CSS code to explain what a particular piece of CSS does, or why a certain style is necessary.
CSS
/* Set main background color */ body { background-color: lightblue; }

Comments like these are helpful when collaborating with team members or reviewing your own code later.


  1. Disable Code: Temporarily disable certain styles by commenting them out.
CSS
body { /* background-color: lightblue; Disable background color */ font-size: 16px; }

  1. Mark TODOs or FIXMEs: Use comments to mark parts of the code that need to be altered or reviewed later. TODO indicates a task to be done, and FIXME indicates something that needs to be fixed.
CSS
/* TODO: Adjust font-size for responsive design */ h2 { font-size: 24px; }

Points to Remember

  • You cannot nest comments within comments with /* or */.

  • Although comments are not rendered by the browser, they are visible in the webpage's source code; therefore, avoid including sensitive information in comments.

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

HTML
CSS
Loading...