It is a common practice to add comments in the code to enhance readability and add helpful notes alongside the code. Like most languages, CSS allows the users to add comments in the stylesheet.
Comments in CSS can be added by using the
/* tag, which is then closed off by using
Note: Code that is commented out is not used to style the page.
This technique can be used to add both single and multi-line comments.
Single line comments can be added as follows:
/* This is a SINGLE LINE COMMENT */
Note: Users may observe that the
//tag can be used to add single line comments. However, this is not the standard practice in CSS and therefore should not be used.
Multi-line comments can be added using the same
/* This is a MULTI LINE COMMENT in CSS */
Let’s add comments to a functioning piece of code and see how it works:
View all Courses