w3resource logo

What is HTML comment - HTML tutorials

HTML comments

Secondary Nav

Description of HTML comment

1. HTML comments stop the HTML code written within it, form being processed while displaying an HTML document in the browser.

2. HTML comments start with "<!--" and end with "-->".

3. HTML comments can be placed anywhere in an HTML document. But our suggestions is , do not place it before DOCTYPE.

4. HTML comment can not be nested, i.e. a comment can not hold another comment within it.

Pictorial presentation of HTML comment

HTML comment

HTML page with some HTML comment

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>An example with HTML elements</title>
<h1>HTML tutorials - w3resource.com</h1>
<p>HTML Elements are key components of an HTML document</p>
<p><a href="/html/html-tutorials.php">Start learning HTML</a></p>
<!--<img src="html-comment.gif" alt="HTMLcomment" />-->
<h3>Write to us</h3>
<form name="demo" action="">
Name: <input type="text"><br><br>
<input type="text"><br><br>
<textarea rows="10" cols="4">
<input type="submit" value="Submit">


HTML tutorials - w3resource.com

HTML Elements are key components of an HTML document

Start learning HTML

Write to us




If you view this HTML comment example in a separate browser window, you will find that the commented code is not being displayed.

Conditional comments

Description of Conditional comments

1. Conditional comments are conditional statements to hide or provide HTML source code from Internet Explorer.

2. There are two types of conditional comments - downlevel-hidden - which is used to hide HTML source and downlevel-revealed which is used to reveal HTML source code in Internet Explorer.

Syntax of Conditional comments

Type Syntax
downlevel-hidden <!--[if expression]> HTML Code<![endif]-->
downlevel-revealed <![if expression]> HTML Code <![endif]>

Operators used in conditional comments

Operators Description
! NOT operator
lt Less than
lte Less than equal to
gt Greater than
gte Greater than equal to
( ) Subexpression, i.e to construct a condition within a condition
& AND operator
| OR operator

Example of conditional comment (downlevel hidden)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of conditional comment (downlevel hidden)</title>
<h1>We are learning conditional comment</h1>
<!--[if lte IE 8]>
<link href="ie8only.css" rel="stylesheet">

View the example of conditional comment (downlevel hidden) in browser.

Example of conditional comment (downlevel revealed)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of conditional comment (downlevel revealed)</title>
<h1>We are learning conditional comment</h1>
<![if !IE]>
<p>You can see this if your borwser is not IE </p>

View the example of conditional comment (downlevel revealed) in browser.

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program