HTML Comments

Comment is a piece of code, which ignored by browser and use of comment make the code simple and easy to understand. Comment increases code readability. It is a good practice to add comments into you HTML code.

A comment must start with . A comment can be placed anywhere in the document and the browser will ignore everything with in the brackets.

Example
<!doctype html
<html
<head> <!-- header start -->
<title>  document title </title
</head> <!-- header end -->
<body>
<p> document content </p>
<body<
<html>
Multiline comments

 You can comment multiple lines by using <!– and end –> .

Example
<!doctype html>
<html>
<head>
<tilte> multi comment </title>
</head>
<body>
<!--
'''''''''''''''
This is a multiline comment
...........
-->
</body>
</html>

Conditional comments
Conditional comments only works in Internet Explorer (IE).

Example
<head>
<!--[if IE6]>
...........
...........
...........
<![endif]-->
</head>
Commenting Script code

Example of JavaScript code inside the comments.

<head>
<script>
<!--
document.Write("JavaScript")
//-->
</script>
</head>
Commenting stylesheets

Example of stylesheets code inside the comments.

<head>
<style>
<!--
.sty {
color: green;
}
//-->
</style>
</head>

Leave a Reply