HTML <!-- ... --> tag

The <!-- ... --> tag is used to insert comments in an HTML code. Browsers ignore its content and do not display it. However, the comments are visible to anyone who views the page source code.

The HTML comments are used to indicate sections of a document or insert any notes explaining the code. The comment tag can also be used to exclude temporary code blocks instead of deleting them.

Comments can be used anywhere in the documents except for the <title> tag.


Comments are written between <! and --> symbols.


<!DOCTYPE html>
    <title>Example of using the comment tag.</title>
    The content of the page. 
    <!-- This is our comment, that is not displayed on the browser. --> 


Conditional Comments

Conditional comments are conditional statements interpreted only by Microsoft Internet Explorer versions 5 through 9 in HTML source code. All other browsers see them as ordinary comments and ignore them.

Syntax of a conditional comment is as follows: <!--[if condition]> <![endif]-->. The code in the tag is executed only if the condition is true.

Conditional comments are no longer supported in IE10 and IE11.


<!--[if lte IE 6]> Instructions for IE less or equal to 6<![endif]-->

Operators and Their Values

Operator Value Example Comment
lt Less than [if lt IE 8] All versions less than IE8.
lte Less or equal to [if lte IE 7] All versions less than IE8.
gt Greater than [if gt IE 7] All versions greater than IE7.
gte Greater or equal [if gte IE 7] IE7, IE8, IE9
& Logical AND. Groups several conditions. Returns true if all conditions are true. [if (gte IE 6) & (lt IE 8)] IE6, IE7.
! Logical NOT. The condition is true if the condition following ! is not executed. [if !(IE 7)] All versions except for IE7.
| Logical OR. Returns true if at least one condition is true. [if (IE 6) | (IE 7)] IE6 and IE7.
() Groups additional conditions. Is used to create complex queries using logical operators. [if !(IE 6) & (lt IE 9)] All versions except for IE6 and IE9.

The comment tag doesn’t support the Global Attributes.

Browser support

Related articles