HTML & CSS - Mastery / HTML Basics

Comments and Best Practices

🧠 What Are Comments?

Comments in HTML let you leave notes or explanations inside your code — without affecting how the webpage looks. They’re invisible in the browser but super helpful for organizing or understanding your code later.

✔Syntax – How to Write a Comment

<!-- This is a comment -->

Everything between <!-- and --> is treated as a comment and won’t be displayed.

📗 Best Practices for Using Comments

  1. Use Comments to Label Sections

<!-- Header Section -->
<header>
  <h1>Welcome</h1>
</header>

Helps you and others know what part of the page you're working on.

  1. Explain Tricky Code (Only When Needed)

<!-- This div keeps the layout centered -->
<div class="container">
  <!-- content -->
</div>
  1. Close Tags with Comments (Helpful in long files)

</section> <!-- End of About Us section -->
  1. Avoid Over-commenting

<!-- This is a paragraph -->  <!-- ❌ Not needed -->
<p>This is a paragraph.</p>

Don’t write comments for things that are obvious.


📑Quick Reminders

  • Comments do not appear on the webpage

  • They don’t affect your layout or design

  • Use them to make your code easier to understand