How to write comment in CSS file?
CSS is a language which describes the style of an HTML document. That is, it describes how the HTML elements should be displayed in the browser.
The CSS Comments are used to differentiate notes from the code. It briefs about the code and helps to edit the source code at a later time. CSS Comments are ignored by browsers and hence they are not visible in the front end. Learn how to comment in CSS (Cascading Style Sheet) file with this simple step by step tutorial. Learn to write single and multi line CSS Comments Syntax.
A CSS comment starts with a preceding backslash followed by an asterisk (/*) and ends with an asterisk and backslash (*/) at the end. Multiple lines can also be included within the /* and */.
Example 1:
p {
color: green;
/* This is an example of single-line comment */
text-align: center;
}
/* This is an
example of
multi-line comment */
We can add as many comments as required. It is a good practice to use comments which helps in understanding the code. Comments make CSS style sheets more legible, readable, understandable and easier to maintain in future.
Everything that is in between the opening and closing comment characters are termed as comments. See the below example.
Example 2:
/************************
*************************
Anything between the opening
and closing comment characters
are considered as comments
*************************
************************/
CSS: Temporary Comments:
While coding in CSS sometimes it will be necessary to remove one or more lines from the code for debugging. We can achieve this by commenting that part of the code which we wish to remove.
Another quick fix is you can put some random characters at the beginning of the line, which logically comments the line.
Example 3:
body {
background-image: url("img_tree.png");
/* background-repeat: no-repeat; */
margin-right: 200px;
}
body {
background-image: url("img_tree.png");
AAAbackground-repeat: no-repeat;
margin-right: 200px;
}
Using the quick fix temporary commenting using random alphabets could be quick and effective only for development and quick debugging purposes. But it is not valid CSS coding practice.