HTML Comment

You are currently viewing HTML Comment

HTML Comment basically something in an HTML document that is completely ignored by the browser. This means even if you will write the comment on your HTML page either on the head, on the body so it will not be reflected as the output in the browser. Because comments’ purpose is to give the information to your colleagues. HTML Comment can help you to understand the source code of other persons.

For example, I’m a web designer in a company and I have written some HTML code and after someday, I come back for some changing/redesign the web pages or some other employees will come for the redesign of the same web page that I have designed. So the comments will help him out why I have put some particular tag or whatever I have done. I can actually keep on explaining for whatever I’m doing while designing a web page inside the comments so it will be basically a good practice to write comments.

When you are working on big documents it will, in fact, help you also out after a few days like today I created a very big document maybe after some time I’ll forget something about it; I can go there again I can read the comments and I will get my information back.

HTML Comment Tag

An HTML Comment is started with <!-- and the comment close with -->. And also you can use the comment tag to comment on the text. The opening tag is <comment> and the closing tag is </comment>. These are the HTML Comment tag that is used to add the comment in the HTML documents.

By using these HTML Comment tag you can make the comment of any piece of text and also you can make the comment any piece of code by using these tags. The HTML comment line is not displayed on the browser as showing in the following example. HTML comment syntax is that start your comment with <!-- and end your comment with -->.

HTML Comment Code Example

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Comment</title>
    <!-- this is the title of the web page -->
  </head>
  <body>
    <div>
      <p>This is Post from wuschools.com and this text is visible</p>
      <!--  
      Hello, world! I am a comment and I am
      displayed in multiple lines!
      --> 
      </div>
  </body>
</html>

Output

html comment

Some Other Examples.

<!DOCTYPE html>
<html>

   <head>
      <title>Valid Comment Example</title>
   </head>
	
   <body>
      <!--   This is valid comment -->
      <p>Document content goes here.....</p>
   </body>
	
</html>
<!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>
Live Demo
<!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.
      -->
      
      <p>Document content goes here.....</p>
   </body>
	
</html>
Live Demo
<!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>
<!DOCTYPE html>
<html>

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

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

   <head>
      <title>Commenting Style Sheets</title>
      
      <style>
         <!--
            .example {
               border:1px solid #4a7d49;
            }
         //-->
      </style>
   </head>
	
   <body>
      <div class = "example">Hello , World!</div>
   </body>
	
</html>

Browser Support

html comment tag support browser

Reference

If you want to learn more about HTML then visit the official website: Visit

Visit the HTML tutorial list. And make strong your HTML concept. Click here. wuschools.com is always written about the HTML concept for the HTML lover. And writes about how HTML makes your life easy if you are a web site developer. We help you to continue your learning.

Leave a Reply