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

The comment tag (<!--...-->) is used to add a note to an HTML document.

Comments are for developers only and users do not see comments.



An HTML comment that will not be 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. Developers call this 'commenting out the code'.

The next 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>

Browser support

When comment support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

Last updated on Sep 30, 2023