Ad – 728Γ—90
🌐 Beginner

HTML Comments

HTML comments let you add notes to your code that the browser ignores completely. Comments are invaluable for explaining why something is structured a particular way, for temporarily disabling markup during debugging, and for marking section boundaries in long HTML files.

⏱️ 8 min read🎯 BeginnerπŸ“… Updated 2026

Comment Syntax

HTML
<!-- This is an HTML comment β€” the browser ignores everything here -->

<!-- Single line comment -->

<!--
  Multi-line comment.
  Everything inside is ignored by the browser.
  Useful for longer explanations.
-->

<p>This paragraph is visible.</p>
<!-- <p>This paragraph is commented out β€” not rendered.</p> -->
<p>This paragraph is also visible.</p>
⚠️
HTML comments are visible in page source

Anyone can view your HTML comments by pressing Ctrl+U (View Source) or using browser DevTools. Never put passwords, API keys, internal notes about bugs, or sensitive business information in HTML comments β€” they are publicly visible.

Ad – 336Γ—280

When to Use Comments

HTML – Good uses of comments
<!-- ===================== HEADER ===================== -->
<header class="site-header">
  <nav>...</nav>
</header>
<!-- =================== END HEADER =================== -->

<!-- ====================== HERO ====================== -->
<section class="hero">
  ...
</section>

<!-- TODO: Replace placeholder image with final product photo -->
<img src="placeholder.jpg" alt="Product photo coming soon">

<!-- NOTE: This div is needed for the JavaScript slider to work.
     Do not remove even though it appears empty. -->
<div id="slider-container"></div>

<!-- Temporarily disabled β€” A/B testing in progress
<div class="old-banner">
  <p>Old promotional message</p>
</div>
-->

Comment Shortcuts

In VS Code, select code and press Ctrl+/ (Windows/Linux) or Cmd+/ (Mac) to toggle HTML comments on/off. This is the fastest way to comment out sections during debugging.

πŸ“‹ Summary

  • Syntax: <!-- comment text --> β€” everything inside is ignored by the browser.
  • Comments are publicly visible in page source β€” never put sensitive data in them.
  • Good uses: section dividers, TODO notes, explaining non-obvious structure, temporarily disabling code.
  • VS Code shortcut: Ctrl+/ to toggle comments on selected HTML.