HTML Comments

HTML Comments Tutotials

1. HTML Comments

Comments are some text or code written in your code to give an explanation about the code, and not visible to the user. Comments which are used for HTML file are known as HTML comments. Anything written between these tags will be ignored by the browser, so comments will not be visible on the webpage.

Comments of any code make code easy to understand and increase readability of code.

Comments are also part of the code, which gives an explanation of the code.

2. How to add comment In HTML

You can add comments in your HTML file using <! -- ... --> tag. So if you will write anything between theses comment tag that will be treated as comment and browser will not read it.

3. Syntax:

<! -- Write commented text here -->  

Such as:

  1. <!--   <p>There is some text</p>  
  2.        <p>There is second text</p> -->  

4. Example:

  1. <!DOCTYPE html>  
  2. <html>  
  3. <!-- This is Header section -->  
  4. <head>  
  5.     <!-- Internal CSS -->  
  6.     <style>  
  7.         body{  
  8.             text-align: center;  
  9.             background-color: #f0f8ff;  
  10.             font-size: 30px;  
  11.             color: red;  
  12.         }  
  13.     </style>  
  14. </head>  
  15.   
  16. <!-- This is body section, write code here which you want to display on web-page -->  
  17. <body>  
  18.     <!-- heading tag -->  
  19.  <h2>First WebPage</h2>  
  20.   
  21.  <!-- Paragraph tag -->  
  22.  <p>Write your Content here!!!</p>  
  23. </body>  
  24. </html>  

5. Multiline Comment

In HTML code, we can also comments multiple lines at a time. In multiline comment we can use any description about code or multiple line code to debug, etc.

6. Syntax:

  1. <!---  
  2. Your code is commented.   
  3. Write description of code.  
  4. It will not display at webpage.   
  5. -->  

7. Example:

    <!DOCTYPE html>  
    <html>  
       <head>  
        
        </head>  
         <body>  
          <h2>Cake Gallery</h2>  
<!-- This is image for a yummy cake  
you can see it on your web-page  
of your favorite browser -->  
<img src="https://static.samtpoint.com/htmlpages/images/icecream.png" alt="icecream image" height="300px"  
 width="300px">  
     </body>  
     </html>