HTML Comment Tag

By Jonathan Griffin. Editor, SEO Consultant, & Developer.

· 2 min read


A <!-- … --> Tag, otherwise known as the comment tag, is used to insert comments in your code. Comments inserted this way are hidden, and do not show to your users.


<!DOCTYPE html>
    <title>HTML Title Element</title>
    <h1>Displayed Page Title</h1>
    <p>The main content of your page goes here.</p>
<!-- This is a comment that is only visible in the source code. -->


  • The comment tag is used to add comments to your code, such as explanations or adding TODO items. This helps you understand your code at a later date.
  • Comments do not nest, so you cannot put a comment inside another comment.


The Anchor tag does not support any attributes, including the Global Attributes and Event Attributes.

Best Practices

  • Single-line Comments should be on one line with the text inside surrounded by spaces.
    <!-- This is a single line comment -->
  • Multi-line Comments should start and end on their own line. The comment text should not be indented..
    This is a multi-line
  • Closing Tag Comments are used to mark the closing of a tag. They should include the class or ID name.
    <div id="section-wrapper">
    </div><!-- #section-wrapper -->
  • Sensitive Information should not be inserted into comments as it is visible to anyone who inspects the source code.
    <!-- Authenticate with password="1234" -->

Browser Support




Android WebviewChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet