Professional Documents
Culture Documents
11-HTML - Comments
11-HTML - Comments
HTML Comments are used to comment in HTML codes, so the developer can understand the
purpose of that code section and it is helpfull for debugging also. If we are facing some issue
becouse of any particular element we cah check it by commenting out that element.
Single Line Comment: The single-line comment is given inside the <!-- ... -->.
Multi Line Comment: Same as single-line comment but if we add multiple lines in the
comment we will have multi-line comments.
Try to click the icon run button to run the following HTML code to see the output.
Here in this example we will use single line comment for each element used in the body tag.
<!DOCTYPE html>
<html>
<head>
<title>Online HTML Editor</title>
</head>
<body>
<!-- This is a single Comment-->
<h1>Tutorialspoint</h1>
<!-- This is a single line Commnet -->
<p>Simply Easy Learning</p>
</body>
</html>
Here in this example we will use multi line comment for each element used in the body tag.
<!DOCTYPE html>
<html>
<head>
<title>Online HTML Editor</title>
</head>
<body>
<!--
This is a multiline Comment
Heading Section
-->
<h1>Tutorialspoint</h1>
<!--
This is a multiline line Commnet
paragrapgh Scetion
-->
<p>Simply Easy Learning</p>
</body>
</html>
Note: We can not use the above approach of commenting on internal CSS and
JavaScript section. In the <style> and <script> tag we have to use CSS and JavaScript
comment syntax.
<!DOCTYPE html>
<html>
<head>
<title>Valid & Invalid Comment</title>
</head>
<body>
<!-- This is valid comment -->
< !-- This is not a valid comment -->
< !-- This is not a valid comment -- >
</body>
</html>
Conditional Comments
Conditional comments are a feature specific to Internet Explorer (IE) on Windows but they are
ignored by other browsers. They are supported from Explorer 5 onwards, and you can use them to
give conditional instructions to different versions of IE.
<!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>