css
  1. css-comments

CSS Comments

  • CSS (Cascading Style Sheets) comments are used to add explanatory notes to the code or to prevent the browser from interpreting specific parts of the style sheet.
  • Comments are used to explain the code and may help when you edit the source code at a later date.
  • Comments are ignored by browsers.

How to Add Comments in CSS

To add a comment in CSS, simply place your plain text inside /* */ marks. This tells the browser that they are notes and should not be rendered on the web page.

Here is an example of how to add a comment in CSS:

/* This is a comment */

This will add a comment to your CSS code.

CSS Comment Syntax

CSS comments can be placed wherever white space is allowed within a style sheet. They can be used on a single line or traverse multiple lines.

The /* */ comment syntax is used for both single and multiline comments.

Here is an example of a multiline comment:

/*
This is a multiline comment.
It can span multiple lines.
*/

Why Use CSS Comments

  • CSS comments are not displayed in the browser, but they can help document your source code.
  • Comments are used to explain the code and may help when you edit the source code at a later date.
  • Adding comments to the code is a good practice that can help to understand the code if someone reads the code or if it is reviewed later.
Published on: