Comments
A comment is a chunk of code that every web browser ignores. It's a good idea to use comments in your HTML code to indicate portions of a page and any additional notes to anyone reading at the code, especially in complex texts. Comments improve code readability and help you and others comprehend your code.
Between<> tags, HTML comments are put. As a result, any material contained within the <> tags will be interpreted as a remark by the browser and will be completely ignored.
Example
<!DOCTYPE html>
<html>
<head> <!-- Document Header Starts -->
<title>This is document title</title>
</head> <!-- Document Header Ends -->
<body>
<p>Document content goes here.....</p>
</body>
</html>
Valid vs Invalid Comments
Comments do not nest, which implies that one remark cannot be nested within another. Second, except as part of the closing --> tag, the double-dash sequence "--" may not exist inside a comment. You must also ensure that the start-of comment string does not contain any spaces.
Example
Here, the given comment is a valid comment and will be wiped off by the browser.
<!DOCTYPE html>
<html>
<head>
<title>Valid Comment Example</title>
</head>
<body>
<!-- This is valid comment -->
<p>Document content goes here.....</p>
</body>
</html>
The next line, on the other hand, is not a valid remark and will be ignored by the browser. There is a space between the left angle bracket and the exclamation mark, which causes this.
<!DOCTYPE html>
<html>
<head>
<title>Invalid Comment Example</title>
</head>
<body>
< !-- This is not a valid comment -->
<p>Document content goes here.....</p>
</body>
</html>
Multiline Comments
We've only seen single-line comments thus far, but HTML also allows for multi-line comments.The special beginning tag <> inserted before the first line and end of the last line, respectively, can be used to comment multiple lines, as seen in the example below.
Example
<!DOCTYPE html>
<html>
<head>
<title>Multiline Comments</title>
</head>
<body>
<!--
This is a multiline comment and it can
span through as many as lines you like.
-->
<p>Document content goes here.....</p>
</body>
</html>
</code></pre>
<br><br>
Conditional Comments
Conditional comments are only supported by Internet Explorer (IE>on Windows; other browsers ignore them. They're available starting with Internet Explorer 5 and can be used to deliver conditional instructions to different versions of the browser.
Example
<!DOCTYPE html>
<html>
<head>
<title>Conditional Comments</title>
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
</head>
<body>
<p>Document content goes here.....</p>
</body>
</html>
You may find yourself in a position where you need to use a separate style sheet for different versions of Internet Explorer; in this case, conditional comments will come in handy.Using Comment Tag Only a few browsers allow you to comment on a section of HTML code using the
Example
<!DOCTYPE html>
<html>
<head>
<title>Using Comment Tag</title>
</head>
<body>
<p>This is <comment>not</comment> Internet Explorer.</p>
</body>
</html>
Commenting Script Code
Though you'll learn how to use JavaScript with HTML in a separate tutorial, keep in mind that if you're using Java Script or VB Script in your HTML code, it's best to enclose the script code inside correct HTML comments so that older browsers can read it.Example
<!DOCTYPE html>
<html>
<head>
<title>Commenting Script Code</title>
<script>
<!--
document.write("Hello World!">
//-->
</script>
</head>
<body>
<p>Hello , World!</p>
</body>
</html>
Commenting Style Sheets
Though you'll learn how to use style sheets with HTML in a separate tutorial, keep in mind that if you're using Cascading Style Sheets (CSS>in your HTML code, it's best to put the CSS code inside correct HTML comments so that older browsers can read it. Example Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Commenting Style Sheets</title>
<style>
<!--
.example {
border:1px solid #4a7d49;
}
//-->
</style>
</head>
<body>
<div class = "example">Hello , World!</div>
</body>
</html>