HTML Comments Tag

The HTML 'comments' tag is used for creating comments within your HTML code.

The comments tag is not actually an HTML element (it is specified elsewhere in the HTML specifications). However, comments are an integral part of any HTML document. They allow the author to add comments that aren't displayed to the end users.

These comments can assist the author in understanding the code. This is particularly useful if there's a lot of code, the author is new to a website, or if the author is modifying an HTML document that he/she hasn't updated for a long time, and needs a reminder about what various parts do.

Syntax

The Comments tag is written as <!-- --> with the comments inserted between the start and end tags. Note that the exclamation mark is only used in the start tag.

Like this:

Examples

Basic tag usage

Multiple Lines

There is no difference between tag usage whether you're commenting out one line or multiple lines. You still insert the comments between the start and end tags. You can even have the start and end tags on their own line. This can make your comments easier to read.

Formatting Comments

Some authors like to include other characters to format their comments and draw attention to certain parts.

Differences Between HTML 4 & HTML 5

None.

Tag Details

For more details about the Comments tag, see HTML5 Comments Tag and HTML4 Comments Tag.

Specifications

Here are the official specifications for the Comments element.

What's the Difference?

W3C creates "snapshot" specifications that don't change once defined. So the HTML5 specification won't change once it becomes an official recommendation. WHATWG on the other hand, develops a "living standard" that is updated on a regular basis. In general, you will probably find that the HTML living standard will be more closely aligned to the current W3C draft than to the HTML5 specification.