NEW

6/recent/ticker-posts

Header Ads Widget

HTML Comments

 

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.

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.

Syntax

  1. <! -- Write commented text here -->  

Note: The commented code will not be visible to a webpage, and hence you can use comment tag for documentation purpose, and debugging purpose:

Such as:

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

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>  


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.

Syntax

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

Example:

  1.  <h2>Cake Gallery</h2>  
  2. <!-- This is image for a yummy cake  
  3. you can see it on your web-page  
  4. of your favorite browser -->  
  5. <img src="https://static.javatpoint.com/htmlpages/images/cake.png" alt="cake image" height="300px"  
  6.  width="300px">  

Output:

HTML Comments



Post a Comment

0 Comments

Recents Post

Exploring Paidwork - Your Gateway to Earning Online