All Types of HTML Comments

HTML comments help organize your code and are ignored by the browser when rendering the page.

Single-Line Comment

<!-- This is a single-line comment -->

Multi-Line Comment

<!--
  This is a multi-line comment.
  It can span over multiple lines.
  Useful for writing long explanations.
-->

Developer Notes (Labelled Comments)

<!-- TODO: Add navigation menu here later -->
<!-- NOTE: This section will be visible to admin only -->
<!-- FIXME: This needs to be fixed for small screens -->

Conditional Comments (for Internet Explorer only — obsolete now)

<!--[if IE]>
  <p>This is Internet Explorer specific content</p>
<![endif]-->

Wrapping a Section with Comment

<!-- Start: Sidebar -->
  <div class="sidebar">
    <p>Sidebar content</p>
  </div>
<!-- End: Sidebar -->

Important Notes

  • HTML doesn't support nested comments. Never do this:
    <!-- <!-- Invalid --> -->
  • Comments are visible in browser “Inspect Element” but not on the page.

VS Code Shortcut

  • Windows/Linux: Ctrl + /
  • Mac: Cmd + /

Add Comments

Output :

Hide Content

Output :

Example

Output :