본문으로 건너뛰기

Comment

Comment

How can you explain specific parts of your CSS code or temporarily disable certain parts?

For this, we use the CSS "comment" feature.


How to Use CSS Comments

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

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

How to Utilize CSS Comments

  1. Code Explanation: You can add comments to CSS code to explain what certain CSS does, why a particular style is necessary, etc.
CSS
/* Setting the main background color */
body {
background-color: lightblue;
}

These comments are helpful when you are collaborating with team members or when you will revisit your code in the future.


  1. Code Disabling: If you wish to temporarily not apply certain styles, you can comment out those parts to disable them.
CSS
body {
/* Disabling the background color CSS */
font-size: 16px;
}

  1. Marking TODOs or FIXMEs: You can use comments to mark parts that should be edited or reviewed later.
CSS
/* TODO: Adjust the font size to fit the responsive design */
h2 {
font-size: 24px;
}

Precautions

  • You cannot use /* or */ again inside CSS comments as it will interfere with the commenting syntax.

  • Although comments do not render in the browser, they can be seen in the web page's source code. Therefore, it's advisable not to include sensitive information within comments.