<!-- ... -->

Adds a comment to an HTML page.
2 min read
Believemy logo

The HTML tag <!--...--> is used to insert comments into the HTML code.

These comments are ignored by browsers and do not appear on the web page. They allow developers to add notes, reminders, or explanations to the code without affecting the document's rendering.

Warning

Warning

Comments are visible to anyone inspecting the source code using:

  • Right-click > View page source
  • Right-click > Inspect

So, never include sensitive information in your comments! 😊

 

Structure

The HTML comment tag consists of an opening <!-- and a closing -->. Everything between these two delimiters is considered a comment. Here’s a simple example:

HTML
<!-- This is a comment -->

They are also used when you want to temporarily hide an element on the page without removing it from the source code:

HTML
<!-- <p>This paragraph is disabled and will not be displayed.</p> -->

 

Syntax

An HTML comment always starts with <!-- and ends with -->.

No spaces are required between the delimiters, but it is recommended to add them for readability.

For example, this works:

HTML
<!--Here-->

However, we prefer to use this:

HTML
<!-- Here -->
Good to know

Comments cannot be nested.

 

Attributes

The <!--...--> tag does not have attributes because it is not a classic HTML tag but a built-in language feature.

 

Compatibility

The <!--...--> instruction is compatible with all browsers.

ElementGoogle ChromeSafariMozilla FirefoxEdge
<!--...-->YesYesYesYes

Related terms

Discover our hTML and CSS glossary

Browse the terms and definitions most commonly used in HTML and CSS development.

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.