14 HTML - Comments
14 HTML - Comments
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.
Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.
Here in this example we will use single line comment for each element used in the body
tag.
https://www.tutorialspoint.com/html/html_comments.htm 1/4
7/17/24, 11:04 AM HTML - Comments
Open Compiler
<!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>
Open Compiler
<!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>
https://www.tutorialspoint.com/html/html_comments.htm 2/4
7/17/24, 11:04 AM HTML - Comments
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.
Open Compiler
<!DOCTYPE html>
<html>
<head>
<title>Hiding p Element</title>
</head>
<body>
<h1>Tutorialspoint</h1>
<!-- <p>Simply Easy Learning</p> -->
</body>
</html>
Open Compiler
<!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 -- >
https://www.tutorialspoint.com/html/html_comments.htm 3/4
7/17/24, 11:04 AM HTML - Comments
</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.
Open Compiler
<!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>
https://www.tutorialspoint.com/html/html_comments.htm 4/4