HTML Comment Tag: <!--...-->

The comment tag (<!--...-->) is used to add a note to an HTML document that is meant for developers only. Users do not see comments.

HTML Tag

Example

#

A comment that is not visible to users.

<!-- A note that documents the code -->

Using comments

The <!--...--> tag treats all its content as HTML comment.

Comments are used to add developer notes that describe the code.

Comments are ignored by the browser and are not shown to the users.

More Examples

The comment is not visible, but the paragraph is.

This paragraph is visible to users.

<!-- This comment is not be visible to users. -->
<p>This paragraph is visible to users.</p>

Note: Comments are not shown to the users, but they do exist in the page source.
Therefore, never include sensitive information, such as passwords, in your comments.


Commenting out the code

Comments are often used to temporarily 'hide' a block of code, until it is revisited at some later point.
In developer speak this is called 'commenting out the code'.

This example demonstrates this practice.
Notice that three text fields are hidden by the browser.





<form action="/tutorial/action.html">
  <input type="text" name="firstname" placeholder="First name"> <br /><br />
  <input type="text" name="lastname" placeholder="Last name"> <br /><br />

<!--
   TODO: review the need for these fields

   <input type="text" name="email" placeholder="Email"> <br />
   <input type="text" name="city" placeholder="City"> <br />
   <input type="text" name="country" placeholder="Country"> <br />
-->
  
  <button type="submit">Submit</button>
</form>

Browser support

When comment support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

Guides