CSS Comments
CSS Comments. Comments are essential for documenting code, providing clarity during development and maintenance. They begin with `/*` and end with `*/`, allowing for multiline or inline annotations. Browsers ignore comments, ensuring they don’t affect the rendering of web pages.
Syntax:
/* content */
Comments can be single-line or multi-line. The /* */ comment syntax can be used for both single and multiline comments. We may use <!– –> syntax for hiding in CSS for older browsers, but this is no longer recommended for use.
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.
Note: The outputs are the same because comments are ignored by the browser and are not interpreted.
Examples of CSS Comments
Example 1: This example describes the single-line comment.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
}
/* Single line comment */
</style>
</head>
<body>
<h1>w3wiki</h1>
<p> A Computer Science portal for Beginner </p>
</body>
</html>
Output:
Example 2: This example describes the multi-line comment.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
}
/* This is a multiline
comment */
</style>
</head>
<body>
<h1>w3wiki</h1>
<p> A Computer Science portal for Beginner </p>
</body>
</html>
Output:
Supported Browsers: