Comments in HTML with Examples

HTML comments are the string text written in source code which helps to provide justification of the HTML text which is not displayed on the webpage of the document. It helps to understand the complexity of the HTML code and assist to find a section of particular HTML source code easily, Let us understand HTML Comments in detail.

Features of HTML Comments

  • HTML Comments are used to help the coder to debug and edit the code for better content to display.
  • HTML Comments helps to find specific information from the source code to eradicate errors.
  • HTML comments are very useful because it does not harm the written HTML text.
  • Temporarily commenting out the HTML text without removing it from the text code is also a feature of HTML comments.
  • HTML comments do not support Attributes.

Syntax of HTML Comment

<!– This is a comment –>

  • HTML comment starts from the open bracket with exclamation mark with double dash and end with the double dash and the content of  the comment between it/
  • The source code text can also be the comment after giving the information between the syntax of the Comment.

Examples of HTML comment

Eg.1 Single -line HTML Comment:

<!DOCTYPE html>
<html>
<body>

<!--  HTML Comment-->
<p>This is codedec.</p>
<!-- ypu cannot see this on the webpage -->

</body>
</html>

output: 

Eg.2 Multi-line HTML Comment:

<!DOCTYPE html> 
<html> 
<head> 
  <title> 
    MULTI-LINE HTML Comment 
  </title> 
</head> 

<body>
  <!-- You cannot see this comment, this tag is very useful for defining HTML codes. 
    
     you cannot see this either  -->
    
  <p>LEARN ON CODEDEC</p> 
</body> 

</html> 

output: