CSS comments can aid in source code documentation even though they are not visible in the browser.
Comments are intended to clarify the code and can come in handy if you ever need to alter the source code.
Browsers don’t read comments.
Within the <style> element is a CSS comment that begins with /* and finishes with */:
/* This is a single-line comment */
p {
color: red;
}
Anywhere in the code, you can add comments:
p {
color: red; /* Set text color to red */
}
Even in the middle of a code line:
p {
color: /*red*/blue;
}
Comments can also span multiple lines:
/* This is
a multi-line
comment */
p {
color: red;
}
You know from the HTML tutorial that the <!–…–> syntax allows you to add comments to your HTML content.
We combine HTML and CSS comments in the example that follows:
My Heading
Hello World!
This paragraph is styled with CSS.
CSS comments are not shown in the output.
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.