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


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

Example of HTML Comment Tag:

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

Example of HTML Comment Tag to hide the JavaScript Code:

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

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