Previous Next

HTML Comments

HTML comments are used for documenting HTML Code.

HTML comments are placed in between <!-- and --> tags.

HTML comments are not rendered on the web browser.

HTML comments can help understand the HTML code.

HTML comments can be defined in any section of HTML Page.

 


 

HTML Comment Example

Example

<!DOCTYPE html>
<html>
   <!-- Document Header Starts -->
<head> <title>Document title</title> </head> <!-- Document Header Ends -->
<body> <p>Document content goes here.....</p> </body> </html>

Result:

Document content goes here.....


 

HTML Multiline Comments

HTML multi-line comments can comment multiple lines.

Anything between beginning tag <!-- and ending tag --> will be commented.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Multiline Comments</title>
   </head>
   <body>
      <!--   
         HTML multi-line comments 
         can comment 
         multiple lines.
         -->
      <p>Document content goes here.....</p>
   </body>
</html>

Result:

Document content goes here.....

 


  

HTML Conditional Comments

Conditional comments only work in Internet Explorer (IE) on Windows.

Conditional comments are ignored by other browsers.

It can be used to give conditional instructions to different versions of IE.

Example

<!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>

 


 

HTML Comment Tag

IE support <comment> tag to comment a part of HTML code.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Using Comment Tag</title>
   </head>
   <body>
      <p>
         This is 
         <comment>not</comment>
         Internet Explorer.
      </p>
   </body>
</html>

Result:

In IE

This is Internet Explorer.

Other Browser

This is not Internet Explorer.

 


  

HTML - Commenting Script Code

Old browsers may not understand JavaScript.

For compatibility, use scripts in comment tags.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Commenting Script Code</title>
      <script>
         <!-- 
            document.write("Hello World!")
         //-->
      </script>
   </head>
   <body>
      <p>Hello , World!</p>
   </body>
</html>

Result:

Hello World!

Hello , World!

 


  

HTML - Commenting Style Sheets

Old browsers may not understand StyleSheets.

For compatibility, use styles in comment tags.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Commenting Style Sheets</title>
      <style>
         <!--
            .example {
              border:1px solid red;
            }
            //-->
      </style>
   </head>
   <body>
      <div class="example">HTML Tutorials!</div>
   </body>
</html>

Result:

HTML Tutorials!

Previous Next