CSS Comment Tag
In this article, we will discuss comments in HTML. In HTML we create everything through a tag But in CSS comment tag is /* */. If we put text in comments browser will skip comments.
What are CSS Comments?
Comments are used so everyone can understand the code, not just a developer. You can write words at the top of your code, to indicate what the code is used for.
HTML and CSS don’t have single-line comments like javascript, so we can always use multiline comments. So even for single-line comments, you need to use multi-line comments. All text you write between /* and */ is treated as comment text. Also if you create a comment (/*) without a closing comment (*/), everything below the opening comment of the CSS page is considered a comment. So, you should write a closing comment.
How to create CSS comment
<html>
<head>
<title>CSS comments</title>
<style type="text/css">
/* Below code is RED box styling */
.div1{
border: 2px black solid;
padding: 15px;
background-color: red;
height: 50px;
width: 50px;
margin: 5px;
}
/* Below code is YELLOW box styling */
.div2{
border: 2px darkred solid;
padding: 15px;
background-color: yellow;
height: 50px;
width: 50px;
margin: 5px;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html>
Output:
In the above code, we have two div elements in HTML. In CSS, We have two stylings but don’t know what they are for so we use comments to say 1st code is for Redbox and 2nd code is for the yellow box. The comment words are never executed in the output.