Page 1 of 8
SQL HTML CSS Javascript Python Java C C++ PHP Scala C#
HTML - Comments
HTML comments are non-executable lines of code that do not display on the webpage and are used
to add notes or explanations. It is a good practice to add comments into your HTML code, especially
in complex documents, to indicate sections of a document and any other notes to anyone looking at
the code.
HTML comments are completely ignored by web browsers, so they don't affect how your page looks
or works.
HTML comments help you and others understand your code and increase code readability and are
placed in between <!-- ... --> tags. So, any content placed with <!--... --> tags will be treated as a
comment and will be completely ignored by the browser.
Example of HTML Comments
Here's an example of HTML comments:
Open Compiler
<!DOCTYPE html>
<html>
<head>
<!-- Document Header Starts -->
Page 2 of 8
<title>This is document title</title>
</head>
<!-- Document Header Ends -->
<body>
<p>Document content goes here.....</p>
</body>
</html>
If you run the above program, it displays the sentence "Document content goes here....." neglecting the
content given as a part of comments.
Powered by:
Valid vs Invalid Comments
Comments in HTML have certain rules that you need to follow. Below is the list of rules −
Comments do not support nesting, which means a comment cannot be put inside another
comment.
You can't have the sequence "--" within a comment, except to close it.
You must also make sure that there are no spaces in the start-of-comment string.
Example
Here, the given comment is a valid comment and will be wiped off by the browser.
Open Compiler
<!DOCTYPE html>
<html>
<head>
<title>Valid Comment Example</title>
</head>
<body>
Page 3 of 8
<!-- This is valid comment -->
<p>Document content goes here.....</p>
</body>
</html>
But the following line is not a valid comment and will be displayed by the browser. This is because
there is a space between the left angle bracket and the exclamation mark.
Open Compiler
<!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
You can comment multiple lines by the special beginning tag <!-- and ending tag --> placed before the
first line and end of the last line as shown in the given example below.
Example
Open Compiler
<!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.
Page 4 of 8
-->
<p>Document content goes here.....</p>
</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.
Example
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>
Page 5 of 8
These tags are used in the situation where you need to apply different style sheets based on different
versions of Internet Explorer; in such a situation, conditional comments will be helpful.
Comments Using <comment> Tag
There are few browsers that support the <comment> tag to comment on a part of HTML code.
Example
Open Compiler
<!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
If an HTML document contains JavaScript or VbScript and you're opening this page on the browser,
some old versions of Browser may not work properly. It is recommended to put that script code inside
proper HTML comments so that old browsers can work properly.
Example
Open Compiler
Page 6 of 8
<!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
To comment a CSS script within a <style> tag, we need to use the /* symbol as a starting point and
the */ symbol as an ending.
Example
Open Compiler
<!DOCTYPE html>
<html>
<head>
<title>Commenting Style Sheets</title>
<style>
/* commenting in stylesheet
.example {
border: 1px solid #4a7d49;
} */
</style>
</head>
<body>
<div class="example">Hello , World!</div>
</body>
</html>
Page 7 of 8
TOP TUTORIALS
Python Tutorial
Java Tutorial
C++ Tutorial
C Programming Tutorial
C# Tutorial
PHP Tutorial
R Tutorial
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
SQL Tutorial
TRENDING TECHNOLOGIES
Cloud Computing Tutorial
Amazon Web Services Tutorial
Microsoft Azure Tutorial
Git Tutorial
Ethical Hacking Tutorial
Docker Tutorial
Kubernetes Tutorial
DSA Tutorial
Spring Boot Tutorial
SDLC Tutorial
Unix Tutorial
CERTIFICATIONS
Business Analytics Certification
Java & Spring Boot Advanced Certification
Data Science Advanced Certification
Cloud Computing And DevOps
Advanced Certification In Business Analytics
Artificial Intelligence And Machine Learning
DevOps Certification
Game Development Certification
Page 8 of 8
Front-End Developer Certification
AWS Certification Training
Python Programming Certification
COMPILERS & EDITORS
Online Java Compiler
Online Python Compiler
Online Go Compiler
Online C Compiler
Online C++ Compiler
Online C# Compiler
Online PHP Compiler
Online MATLAB Compiler
Online Bash Compiler
Online SQL Compiler
Online Html Editor
ABOUT US | OUR TEAM | CAREERS | JOBS | CONTACT US | TERMS OF USE |
PRIVACY POLICY | REFUND POLICY | COOKIES POLICY | FAQ'S
Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical
and non-technical subjects.
© Copyright 2025. All Rights Reserved.