HTML Comment Tag, Example, Syntax

It is very easy to add an HTML comment tag within the HTML documents source code. It is used to hide some informative text while explaining different codes or JavaScript code from the browser. It’s like a label that has a beginning and an end tag. All the text that you put inside the comment tag will not appear on the display webpage.

The comment starts with <!– and ends with–> Everything you put between these labels is commented.

Read also: HTML Tags complete list

Syntax:

<!-- you can write a comment here -->

Example of HTML Comment Tag:

<!DOCTYPE html>
<html>
   <head>
        <!-- This is a head section -->
        <title> Title text goes here… </title>
  </head>
  <body>
            <!-- This is a body section -->
            <p> body text goes here…</p>
  </body>
</html>

Example of HTML Comment Tag to hide the JavaScript Code:

<script type="text/javascript">
<!--JavaScript code here//-->
</script>

The two forwarded slashes (//) must be put just after the JavaScript code. It prevents the JavaScript code from execution.

Browsers Support HTML Comment Tag

  • Inter Explorer (all)
  • Google Chrome (all)
  • Firefox (all)
  • Safari (all)
  • Opera (all)

Similar Posts