Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

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.

Example

#

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>
</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


Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides