Comment
How do you add explanations to specific parts of your code or temporarily disable certain parts when writing CSS code?
In such cases, you can 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; }
How to Use CSS Comments
Code Explanation
: You can add comments to your CSS code to explain the functionality of certain styles or why specific styles are necessary.
CSS
/* Set the main background color */ body { background-color: lightblue; }
Such comments are helpful when collaborating with team members or when reviewing your code later.
Disable Code
: If you want to temporarily prevent a specific style from being applied, you can comment it out to deactivate it.
CSS
body { /* background-color: lightblue; deactivated background color */ font-size: 16px; }
Mark TODO or FIXME
: Use comments to indicate parts of the code that need to be fixed or reviewed later. TODO indicates tasks to be done later, while FIXME indicates parts that need fixing.
CSS
/* TODO: Adjust font size for responsive design */ h2 { font-size: 24px; }
Caution
-
You cannot use
/*
or*/
within a CSS comment. -
Comments are not rendered by the browser, but they are visible in the source code of the web page, so it is advisable not to include sensitive information in comments.
Mission
0 / 1
What should you use to explain or disable specific parts of CSS code?
HTML tags
JavaScript functions
CSS comments
CSS selectors
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help