English العربية Português Japanese

HTML Comments

Comments are text notes written for developers. Browsers completely ignore them. Using comments wisely can dramatically improve code readability and facilitate team collaboration.

Comment Syntax

HTML comments begin with <!-- and end with -->. The content in between can be any text; the browser will not display it on the page:

HTML
<!-- This is a comment, users can't see me -->
<p>This text is visible to users.</p>

<!-- ======= Navigation Section Start ======= -->
<nav>
  <a href="index.html">Home</a>
  <a href="about.html">About Us</a>
</nav>
<!-- ======= Navigation Section End ======= -->
▶ Try It Yourself
📌 Note: Although comment content is not visible on the page, it still appears in the HTML source code — anyone can see your comments by viewing the page source. Never include passwords or sensitive information in comments.

Common Uses of Comments

Comments aren't just for writing notes — they're also very useful during development and debugging:

HTML
<!-- Temporarily comment out a section of code (for debugging) -->
<!--
<p>This code doesn't need to be displayed for now.</p>
<a href="old-page.html">Old Link</a>
-->

<!-- TODO: Need to add user avatar later -->
<!-- @John 2026-06-12: Confirm the copy here before going live -->
▶ Try It Yourself
💡 Best Practice: Comments should explain why something is written a certain way, not how it's written. Good code should be self-explanatory; comments only supplement context that the code itself cannot express. Also, remember to clean up debugging comments before going live.

📖 Summary

📝 Exercises

  1. Add comments to your code: Write a simple page with navigation and body content, adding section comment markers before and after each block (e.g., <!-- Navigation Start -->).
  2. Comment-based debugging: Copy the code from a previous lesson and use comments to temporarily "hide" a section. Verify that the hidden section is indeed not displayed on the page.
100%